Reputation: 2118
In my asp.net page I'm making a copy of a file from my local drive to the server.
'append the name to the id number and generate the file name
strFileName = System.Configuration.ConfigurationManager.AppSettings("strAttachmentsPath") & l.ToString & "_" & CType(Session("FileName"), String)
'upload the file
'FileUpload1.SaveAs(strFileName)
System.IO.File.Copy(CType(Session("Attachment"), String), strFileName, True)
strFileName
contains a server path like "\\myServer\images\theNewFileName.jpg"
Session("Attachment")
contains my local path 'C:\Users\myUser\Desktop\AccountsFrance.txt'
But when I run this code asp.net throws an exception:
But I can browse to this file easily.... I dont understand why this is happening :(
Upvotes: 3
Views: 1228
Reputation: 10614
Assuming permissions are set for Network Service to write the destination directory, do a
strFileName = Server.MapPath(System.Configuration.ConfigurationManager.AppSettings("strAttachmentsPath") & l.ToString & "_" & CType(Session("FileName"), String))
to the directory and see if you still get the permissions problem.
Also, what is the value of Session("Attachment") ? That needs to be a file path on the server, not the user's side. Typically, in upload scenarios, you take the byte[] from the upload control and write it to a stream on the server. You could then take that file path and copy it somewhere else.
Upvotes: 2