Last post Oct 18, 2017 04:43 PM by PatriceSc
Oct 17, 2017 11:46 PM|alihusain_77|LINK
Headache problem when perform copying file from folder to another folder. I am trying to copy from source folder where it has the storage of the pdf files to local computer folder that created manually in Windows Explorer and placed as one of the website
folders "~\pdfDirectory\". The actual path of this temporary folder is (D:\ASP_Projects\TrackingDesk\PdfDirectory) , However, I can't put the full path in the code because the IIS prevent the directory browsing of folders and files, thus I am forced to put
it as "~\PdfDirectory". So how can I manage it smoothly and what is the best practices to perform the copy? BTW, I don't know why I can't uncheck the newly created temp folder "Read only", where it continuously turned on as Read only!
So What is the best practices to solve the problem by directly showing me how my code supposed to be with deep thanks and regars:
AttachmentFileServerPath = TheServerPath & LetterID & ".pdf"
AttachmentFileLocalPath = "~\pdfDirectory\" & LetterID & ".pdf"
If System.IO.File.Exists(AttachmentFileServerPath) = True Then
If System.IO.File.Exists(AttachmentFileLocalPath) = True Then
GetTheAttachmentLink = "~\pdfDirectory\" & LetterID & ".pdf"
Oct 18, 2017 12:32 AM|PatriceSc|LINK
So your code is really looking for a ~ folder somewhere which is not found causing this error.
~ is the "application root" in a virtual path and you have to use Server.MapPath to transform a virtual path such as ~/folder/here/file.txt to a physical path such as d:\mysites\thisone\folder\here\file.txt.
If IIS is not allowed to write to this directory the problem is not in trying to access to this folder using some other path but rather to give IIS the needed permissions to write to this directory. My personal preference is to separate my site and my data.
Edit: try https://support.microsoft.com/en-us/help/326549/you-cannot-view-or-change-the-read-only-or-the-system-attributes-of-fo
In short having a read only attribute on a folder shouldn't prevent anything. More likely the account that runs your IIS app is really not having the needed security permissions on this folder and you would really need to grant rw access to this folder for
Oct 18, 2017 02:07 PM|alihusain_77|LINK
I want to create local temp folder under the main drive C:\
Oct 18, 2017 04:43 PM|PatriceSc|LINK
And ? you are looking for
Also the account that will create this directory needs to be allowed to do so.
What if you create this directory by hand and then first make your code work. You'll always be able to add this c:\temp directory creating later if really needed.
For now the core problem is that you are not using a valid file path (as it contains a ~ character that is used with a special meaning only in virtual path).