Issue in Uploading files using FileInfo
-
Hello, I am trying to upload files using CopyTo function of FileInfo. The code I am using is as follows...
FileInfo fileObj = new FileInfo(filUpload1.PostedFile.FileName);
string fileType = filUpload1.PostedFile.ContentType;
string newFileName = "test.txt";string folderPath = System.Web.Hosting.HostingEnvironment.MapPath("~/Uploads");
fileObj.CopyTo(folderPath + "\\" + newFileName);
The exception I am getting is... Could not find file 'C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\help.txt'. Help.txt is the name of the file I selected using FileUpload control. I could have used the SaveAs function of FileUpload control but I want to try it using above method. The files gets successfully uploaded when I do it on my machine but after uploading it on web server, it throws the above exception. Please suggest. Thank You.
-
Hello, I am trying to upload files using CopyTo function of FileInfo. The code I am using is as follows...
FileInfo fileObj = new FileInfo(filUpload1.PostedFile.FileName);
string fileType = filUpload1.PostedFile.ContentType;
string newFileName = "test.txt";string folderPath = System.Web.Hosting.HostingEnvironment.MapPath("~/Uploads");
fileObj.CopyTo(folderPath + "\\" + newFileName);
The exception I am getting is... Could not find file 'C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\help.txt'. Help.txt is the name of the file I selected using FileUpload control. I could have used the SaveAs function of FileUpload control but I want to try it using above method. The files gets successfully uploaded when I do it on my machine but after uploading it on web server, it throws the above exception. Please suggest. Thank You.
Well Mr. Lucknow, The reason behind this exception is that it is trying to find the file to be copied (in your case, it is help.txt) on the web server where it is not present. In short, you can use this way to upload file to the web server. :rose: