c# - DirectoryNotFoundException error while copying the file -


i trying develop web application send file server (in case server local one). when try send file, gives:

directorynotfoundexception: not find part of path.

i have verified folder exists. , ensure, create directory before copying still error. please? here code:

string filename = system.io.path.getfilename("c:\\test\\sample.txt"); string savelocation = httpcontext.current.server.mappath("uploadfile") + "\\";  if (system.io.directory.exists(savelocation)) {      system.io.directory.createdirectory(savelocation);      system.io.file.copy("c:\\test\\sample.txt", savelocation, true); } 

the value of savelocation is:

c:\users\nerd\documents\visual studio 2012\projects\webapplication3\webapplication3\uploadfile\

the system.io.file.copy needs second argument path file , not path directory. adjust code include name want file saved.

string filename = system.io.path.getfilename("c:\\test\\sample.txt"); string savelocation = httpcontext.current.server.mappath("uploadfile") + "\\";  if (system.io.directory.exists(savelocation)) {      system.io.directory.createdirectory(savelocation);      system.io.file.copy("c:\\test\\sample.txt", savelocation + "sample.txt", true); } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -