Reputation: 33
I am trying to upload a file in asp.net using the following code
Dim FileName As String = System.IO.Path.GetFileName(ClientFileName)
MyFile.PostedFile.SaveAs(Server.MapPath("~/UploadedImportedFiles/" + FileName))
if the file being uploaded (say book1.xls) resides on the machine that is also the server all works perfectly, but if the file resides on a Pc that is not the server it fails on the second line. I think the problem is that Server.MapPath seems to refer to the non server PC when it is uploaded from there.
Thanks
Upvotes: 0
Views: 995
Reputation: 19828
You wrongly getting file name. You should use below code
string filename = Path.GetFileName(FileUploadControl.FileName);
Of course change control name to your own.
Please See: http://msdn.microsoft.com/en-us/library/aa479405.aspx
Upvotes: 1