I am using the code below to save a file to a network location. It works in development and on the webserver. But if I go to a client machine using my login credentials, the file isnt saved? I have my app pool set to run under my credentials so that should
be the issue. Any ideas? Thanks!
If FileUpload1.HasFile Then
Try
FileUpload1.SaveAs("\\Server\data\Files\" + FileUpload1.FileName)
Catch ex As Exception
End Try
Else
'Label1.Text = "You have not specified a file."
End If
If FileUpload1.HasFile Then
Try
Dim filepath As String = Server.MapPath("\\\\Server\\data\\files\\" + FileUpload1.FileName)
FileUpload1.SaveAs(filepath)
Catch ex As Exception
End Try
Else
'Label1.Text = "You have not specified a file."
End If
Don't make it to the server. When you use the Server.MapPath() it's going to map it to the root folder. You can also try to make sure the mapping is correct and using an @ so that it knows it's a literal path like this below or use a tilde to make sure it
maps correctly.
You app is runing in IIS? If yes in IIS is configured windows authentication? And this user have permission in you shared folder in the network? This user should write permission.
I hope this help.
Kindly mark this post as "Answer", if it helped you.
Marked as answer by MKozlowski on May 01, 2012 12:46 PM
I have tried all the suggestions no luck. It is uploading the file to a different server then my webserver. The permissions are set and it only saves the file on my development machine. Impersonation is enabled. Not sure what I am missing??
If FileUpload1.HasFile Then
Try
FileUpload1.SaveAs("\\Server\Data\Files\" + FileUpload1.FileName)
Catch ex As Exception
End Try
Else
'Label1.Text = "You have not specified a file."
End If
MKozlowski
Member
500 Points
573 Posts
FileUpload1.SaveAs does not work correctly?
Apr 30, 2012 07:44 PM|LINK
Hi,
I am using the code below to save a file to a network location. It works in development and on the webserver. But if I go to a client machine using my login credentials, the file isnt saved? I have my app pool set to run under my credentials so that should be the issue. Any ideas? Thanks!
If FileUpload1.HasFile Then Try FileUpload1.SaveAs("\\Server\data\Files\" + FileUpload1.FileName) Catch ex As Exception End Try Else 'Label1.Text = "You have not specified a file." End Ifwebguy07
Participant
942 Points
234 Posts
Re: FileUpload1.SaveAs does not work correctly?
Apr 30, 2012 08:31 PM|LINK
if (FileUpload1.HasFile) { try { FileUpload1.SaveAs(Server.MapPath("\\\\Server\\data\\Files\\" + FileUpload1.FileName)); } catch (Exception ex) { } } else { //Label1.Text = "You have not specified a file." }MKozlowski
Member
500 Points
573 Posts
Re: FileUpload1.SaveAs does not work correctly?
Apr 30, 2012 08:42 PM|LINK
I tried that, still the file didnt get saved?
If FileUpload1.HasFile Then Try Dim filepath As String = Server.MapPath("\\\\Server\\data\\files\\" + FileUpload1.FileName) FileUpload1.SaveAs(filepath) Catch ex As Exception End Try Else 'Label1.Text = "You have not specified a file." End Ifwebguy07
Participant
942 Points
234 Posts
Re: FileUpload1.SaveAs does not work correctly?
Apr 30, 2012 09:04 PM|LINK
Don't make it to the server. When you use the Server.MapPath() it's going to map it to the root folder. You can also try to make sure the mapping is correct and using an @ so that it knows it's a literal path like this below or use a tilde to make sure it maps correctly.
Server.MapPath(@"c:\\data\\files\\");
~/data/files/" + FileUpload1.FileName);
MKozlowski
Member
500 Points
573 Posts
Re: FileUpload1.SaveAs does not work correctly?
Apr 30, 2012 09:52 PM|LINK
So would I do Server.MapPath(@\\server\data\files) ?
Or server.mappath(@"~/data/files/")
Thank you
mm10
Contributor
6395 Points
1182 Posts
Re: FileUpload1.SaveAs does not work correctly?
Apr 30, 2012 10:05 PM|LINK
Server.Mappath(@"~/data/files/") if you have a data folder with a files folder at the root of your web application.
pierrefrc
Participant
947 Points
201 Posts
Re: FileUpload1.SaveAs does not work correctly?
May 01, 2012 01:16 AM|LINK
Hi
You app is runing in IIS? If yes in IIS is configured windows authentication? And this user have permission in you shared folder in the network? This user should write permission.
I hope this help.
Deepak_Talel...
Member
458 Points
87 Posts
Re: FileUpload1.SaveAs does not work correctly?
May 01, 2012 04:35 AM|LINK
To save the file, the folder must be shared and the NETWORK SERVICE account should have read/write persmission on the folder.
Also try be setting impersonation tag in web.config
Let me know if this resolves your issue
Ph: 91-9158413830
Email: deepak_talele@hotmail.com, deepak_talele@yahoo.com
MKozlowski
Member
500 Points
573 Posts
Re: FileUpload1.SaveAs does not work correctly?
May 01, 2012 12:34 PM|LINK
I have tried all the suggestions no luck. It is uploading the file to a different server then my webserver. The permissions are set and it only saves the file on my development machine. Impersonation is enabled. Not sure what I am missing??
If FileUpload1.HasFile Then Try FileUpload1.SaveAs("\\Server\Data\Files\" + FileUpload1.FileName) Catch ex As Exception End Try Else 'Label1.Text = "You have not specified a file." End IfMKozlowski
Member
500 Points
573 Posts
Re: FileUpload1.SaveAs does not work correctly?
May 01, 2012 12:46 PM|LINK
I changed the share to the webserver and it is working now. I will just go with that.