Soluga
asked on
Published web app causes error when creating a directory
Hi,
I have the code below which copies a directory structure and works just fine in a development environment. But when I publish the web app and access it and run the page which executes the code then I get an internal server error! I have spent 2 days on this and would be grateful for any advice, I am thinking it must be a permission issue.
Thanks
I have the code below which copies a directory structure and works just fine in a development environment. But when I publish the web app and access it and run the page which executes the code then I get an internal server error! I have spent 2 days on this and would be grateful for any advice, I am thinking it must be a permission issue.
Thanks
Public Function CopyMediaDirectory(ByVal directorySource As String, ByVal directoryDestination As String) As String Implements IM05_PublishedOnlineCourseManager.CopyMediaDirectory
Dim source As New DirectoryInfo(Server.MapPath("../" & directorySource))
Dim destination As New DirectoryInfo(Server.MapPath("../" & directoryDestination))
If Not destination.Exists Then
destination.Create()
End If
' Copy all files.
Dim files As FileInfo() = source.GetFiles()
For Each file As FileInfo In files
file.CopyTo(Path.Combine(destination.FullName, file.Name))
Next
' Process subdirectories.
Dim dirs As DirectoryInfo() = source.GetDirectories()
For Each dir As DirectoryInfo In dirs
' Get destination directory.
Dim destinationDir As String = Path.Combine(destination.FullName, dir.Name)
' Call CopyDirectory() recursively.
CopyMediaDirectory(directorySource & "/" & dir.ToString(), destinationDir)
Next
Return "foldersComplete"
End Function
First thing to do is switch off the "Show Friendly HTTP Errors" in your browser - you will then be shown the actual error message.
It could be a couple of things - firstly Parent Paths could be disabled in IIS. This tells you how to check for, and enable, the setting: http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/40993ff2-22c3-48a9-ba01-1056a9425a1e.mspx?mfr=true
If it is purely a permissions issue then you will need to make sure that the account running the IIS service has permissions to write to your target directory (this may not be the service account if you are using impersonation)
It could be a couple of things - firstly Parent Paths could be disabled in IIS. This tells you how to check for, and enable, the setting: http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/40993ff2-22c3-48a9-ba01-1056a9425a1e.mspx?mfr=true
If it is purely a permissions issue then you will need to make sure that the account running the IIS service has permissions to write to your target directory (this may not be the service account if you are using impersonation)
ASKER
I am getting the error below in the compiled version
The given path's format is not supported.
This is the format I am using..
D:\mywebs\theFolder\myweb. WebUI\Comp anyMediaPu blished\14 1a9a54-a3a b-440f-91c 1-38eb1631 0b26\D6084 1BA-240C-4 68D-9B1A-0 2887F6FBED E
The given path's format is not supported.
This is the format I am using..
D:\mywebs\theFolder\myweb.
Dim source As New DirectoryInfo(Server.MapPath("../" & directorySource))
Line 83: Dim destination As New DirectoryInfo(Server.MapPath("../" & directoryDestination))
ASKER
I think the problem maybe because the code being executed is in my BL and should be in the UI layer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
carl_town your last post got me to thinking about if the file path was changing if the site is not running under the base wwwroot folder.
I scrapped the server.mappath and changed it to....
Dim source As New DirectoryInfo(Path.Combine (HttpRunti me.AppDoma inAppPath, directorySource))
Dim destination As New DirectoryInfo(Path.Combine (HttpRunti me.AppDoma inAppPath, directoryDestination))
This finally works.
3 days!! feck.
Thanks for your help.
I scrapped the server.mappath and changed it to....
Dim source As New DirectoryInfo(Path.Combine
Dim destination As New DirectoryInfo(Path.Combine
This finally works.
3 days!! feck.
Thanks for your help.
It would be better if you could look in to the server log and find out what is the actual error message for the internal error you received.
Regards.