{"id":15900,"date":"2022-10-13T11:48:04","date_gmt":"2022-10-13T06:18:04","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-copying-local-file-to-network-shared-drive-issues\/"},"modified":"2022-10-13T11:48:04","modified_gmt":"2022-10-13T06:18:04","slug":"solved-copying-local-file-to-network-shared-drive-issues","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-copying-local-file-to-network-shared-drive-issues\/","title":{"rendered":"[Solved] Copying local file to network shared drive issues"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-15801922\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"15801922\" data-parentid=\"15801748\" data-score=\"13\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>Ok, let&#8217;s work on this code a little. First let&#8217;s simplify building the paths. We have a network path <strong>and<\/strong> a local path. According to your current code the network path is built with a few variables <code>comboBox1<\/code>, <code>comboBox2<\/code>, and <code>Environment.UserName<\/code>, so let&#8217;s do it a little different:<\/p>\n<pre><code>var networkPath = Path.Combine(@\"\\\\network\",\n    comboBox1.SelectedItem as string,\n    comboBox2.SelectedItem as string,\n    Environment.UserName);\n<\/code><\/pre>\n<p>that&#8217;s going to place the <code>\\<\/code> in between each of those strings properly (i.e. if there were already a back slash it wouldn&#8217;t add one, but would if necessary).<\/p>\n<p>Now let&#8217;s do the same for the local path:<\/p>\n<pre><code>var localPath = Path.Combine(@\"C:\\Users\",\n    Environment.UserName,\n    \"test\",\n    label5.Text);\n<\/code><\/pre>\n<p>ok, we&#8217;re almost there, but we also have an alternative network path:<\/p>\n<pre><code>var alternativeNetworkPath = Path.Combine(@\"\\\\atlanta2-0\\it-documents\\filestroage\",\n    comboBox1.SelectedItem as string,\n    comboBox2.SelectedItem as string,\n    Environment.UserName,\n    label5.Text);\n<\/code><\/pre>\n<p>now, one thing about this path that&#8217;s already suspect to me is this, <code>\\filestroage<\/code>, that&#8217;s actually spelled wrong. Now, if the folder is spelled that way fine, but I&#8217;m wondering if it&#8217;s spelled wrong. So just take a look. Alright, let&#8217;s continue on, now we have all three paths built, it&#8217;s a little easier to read, and we can easily output those strings to <strong>ensure<\/strong> they are right. Let&#8217;s take a look at the logic. It says this, <strong>if the <code>networkPath<\/code> exists then save it there<\/strong>, however, <strong>if it does not exist then create it and save it to the <code>alternativeNetworkPath<\/code>.<\/strong> So let&#8217;s do that:<\/p>\n<pre><code>if (Directory.Exists(networkPath))\n{\n    File.Copy(localPath, networkPath);\n}\nelse\n{\n    Directory.CreateDirectory(networkPath);\n    File.Copy(localPath, alternativeNetworkPath);\n}\n<\/code><\/pre>\n<p>alright, simple enough yes? But you stated that the <code>Directory.Exists<\/code> is returning true <code>even if it exists<\/code>. That&#8217;s pretty much expected isn&#8217;t it? If the directory exists then this method would certainly return <code>true<\/code>, if not then it would return <code>false<\/code>. You then stated with the <code>Directory.CreateDirectory<\/code> that <code>The line above says the network name cannot be found<\/code> &#8211; <strong>that can only mean that the path was constructed wrong.<\/strong><\/p>\n<p>So after breaking it down, the bottom line is this, the paths being constructed have to be off a tidge. However, with this new model you should be able to pull those paths out <strong><em>a lot easier.<\/em><\/strong> So the entire method, in my mind, would look something like this:<\/p>\n<pre><code>var networkPath = Path.Combine(@\"\\\\network\",\n    comboBox1.SelectedItem as string,\n    comboBox2.SelectedItem as string,\n    Environment.UserName);\n\nvar localPath = Path.Combine(@\"C:\\Users\",\n    Environment.UserName,\n    \"test\",\n    label5.Text);\n\nvar alternativeNetworkPath = Path.Combine(@\"\\\\atlanta2-0\\it-documents\\filestroage\",\n    comboBox1.SelectedItem as string,\n    comboBox2.SelectedItem as string,\n    Environment.UserName,\n    label5.Text);\n\nif (Directory.Exists(networkPath))\n{\n    File.Copy(localPath, networkPath);\n}\nelse\n{\n    Directory.CreateDirectory(networkPath);\n    File.Copy(localPath, alternativeNetworkPath);\n}\n<\/code><\/pre>\n<p>and so now let&#8217;s have a look at those paths in those variables and your problem should come right out.<\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\"><\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Copying local file to network shared drive issues <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] Ok, let&#8217;s work on this code a little. First let&#8217;s simplify building the paths. We have a network path and a local path. According to your current code the network path is built with a few variables comboBox1, comboBox2, and Environment.UserName, so let&#8217;s do it a little different: var networkPath = Path.Combine(@&#8221;\\\\network&#8221;, comboBox1.SelectedItem as &#8230; <a title=\"[Solved] Copying local file to network shared drive issues\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-copying-local-file-to-network-shared-drive-issues\/\" aria-label=\"More on [Solved] Copying local file to network shared drive issues\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[324,959],"class_list":["post-15900","post","type-post","status-publish","format-standard","hentry","category-solved","tag-c","tag-winforms"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Copying local file to network shared drive issues - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-copying-local-file-to-network-shared-drive-issues\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Copying local file to network shared drive issues - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] Ok, let&#8217;s work on this code a little. First let&#8217;s simplify building the paths. We have a network path and a local path. According to your current code the network path is built with a few variables comboBox1, comboBox2, and Environment.UserName, so let&#8217;s do it a little different: var networkPath = Path.Combine(@&quot;\\network&quot;, comboBox1.SelectedItem as ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-copying-local-file-to-network-shared-drive-issues\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-13T06:18:04+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-copying-local-file-to-network-shared-drive-issues\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-copying-local-file-to-network-shared-drive-issues\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Copying local file to network shared drive issues\",\"datePublished\":\"2022-10-13T06:18:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-copying-local-file-to-network-shared-drive-issues\/\"},\"wordCount\":355,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"c++\",\"winforms\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-copying-local-file-to-network-shared-drive-issues\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-copying-local-file-to-network-shared-drive-issues\/\",\"name\":\"[Solved] Copying local file to network shared drive issues - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-10-13T06:18:04+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-copying-local-file-to-network-shared-drive-issues\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-copying-local-file-to-network-shared-drive-issues\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-copying-local-file-to-network-shared-drive-issues\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Copying local file to network shared drive issues\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Copying local file to network shared drive issues - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-copying-local-file-to-network-shared-drive-issues\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Copying local file to network shared drive issues - JassWeb","og_description":"[ad_1] Ok, let&#8217;s work on this code a little. First let&#8217;s simplify building the paths. We have a network path and a local path. According to your current code the network path is built with a few variables comboBox1, comboBox2, and Environment.UserName, so let&#8217;s do it a little different: var networkPath = Path.Combine(@\"\\network\", comboBox1.SelectedItem as ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-copying-local-file-to-network-shared-drive-issues\/","og_site_name":"JassWeb","article_published_time":"2022-10-13T06:18:04+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-copying-local-file-to-network-shared-drive-issues\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-copying-local-file-to-network-shared-drive-issues\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Copying local file to network shared drive issues","datePublished":"2022-10-13T06:18:04+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-copying-local-file-to-network-shared-drive-issues\/"},"wordCount":355,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["c++","winforms"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-copying-local-file-to-network-shared-drive-issues\/","url":"https:\/\/jassweb.com\/solved\/solved-copying-local-file-to-network-shared-drive-issues\/","name":"[Solved] Copying local file to network shared drive issues - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-10-13T06:18:04+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-copying-local-file-to-network-shared-drive-issues\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-copying-local-file-to-network-shared-drive-issues\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-copying-local-file-to-network-shared-drive-issues\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Copying local file to network shared drive issues"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775798750","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/15900","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=15900"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/15900\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=15900"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=15900"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=15900"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}