I Have Created Application Which Connects to Virtual Folder And Download Images Which Works Fine Locally But On The Server it Gives Me That Error

System.Net.WebException: An exception occurred during a WebClient request. ---> System.IO.DirectoryNotFoundException: Could not find a part of the path 'J:\CZImages\ Folder\2516_1(0).JPG'. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access) at System.Net.WebClient.DownloadFile(Uri address, String fileName) --- End of inner exception stack trace --- at System.Net.WebClient.DownloadFile(Uri address, String fileName) at System.Net.WebClient.DownloadFile(String address, String fileName) at CZ._Default.btnSave_Click(Object sender, EventArgs e)

And Here IS My Code

string urlToDownload = "http://www.example.com/Images/1111(1).JPG";
// May be you need to add some code to determine the type of the image
StringBuilder ImgName = new StringBuilder();
ImgName.Append(urlToDownload.Remove(0, urlToDownload.LastIndexOf('/') + 1));
string pathToSave = txtPath.Text + "\\" + ImgName;
ImgName.Length = 0;
ImgName.Capacity = 0;
WebClient client = new WebClient();
client.DownloadFile(urlToDownload, pathToSave);

Related posts

Recent Viewed