Can not copy fie to the server.
-
Hi Friends, I am have been facing a strange problem since long time. I have tried to find its solution from many places but I could not succeed. The problem is like following. I my web application I am providing facility to upload images to the server. I have managed to open the file open dialoge box using "File" control of html and get the select file path in a server side text. Now I am copyiny that file to the server by following code. FileInfo fImageFile = new FileInfo(txtCompImagePath.Text); if(fImageFile.Exists) { fImageFile.CopyTo(MapPath(ImageDirPath + "/"fImageFile.Name, true); } Everything works fine until user selects his image from the folder My Folder of from the Desktop. I mean when user select image from My Documents of from the Desktop the fImageFile.Exists returns false that means is tells that the file with specified path is not there. If user select image from any other folder from any drive it works fine and file copying goes smoothly but Images from My documents and Desktop folders could not be copied. and moreover I woder why is shows that the file doesnt exist while the file resides the physically. Can any please tell the cause and solution for this? Thanks to all of you in advance. Chetan Ranpariya
-
Hi Friends, I am have been facing a strange problem since long time. I have tried to find its solution from many places but I could not succeed. The problem is like following. I my web application I am providing facility to upload images to the server. I have managed to open the file open dialoge box using "File" control of html and get the select file path in a server side text. Now I am copyiny that file to the server by following code. FileInfo fImageFile = new FileInfo(txtCompImagePath.Text); if(fImageFile.Exists) { fImageFile.CopyTo(MapPath(ImageDirPath + "/"fImageFile.Name, true); } Everything works fine until user selects his image from the folder My Folder of from the Desktop. I mean when user select image from My Documents of from the Desktop the fImageFile.Exists returns false that means is tells that the file with specified path is not there. If user select image from any other folder from any drive it works fine and file copying goes smoothly but Images from My documents and Desktop folders could not be copied. and moreover I woder why is shows that the file doesnt exist while the file resides the physically. Can any please tell the cause and solution for this? Thanks to all of you in advance. Chetan Ranpariya
I am not familiar with the way you're uploading the files and the problems sounds really weird... but here is the best way to upload a file by using the FileUpload control:
if (oFile.PostedFile != null) { string fullFileName = oFile.PostedFile.FileName; string fileName = System.IO.Path.GetFileName(fullFileName); oFile.PostedFile.SaveAs(Server.MapPath(string.Empty) + "\\" + fileName); }
this code will upload the file to the requested directory... (you can easily change the saving directory by editing the parameter in the SaveAs function..) and it should work with no problems... Good luck, Tal Kain.