Solved

Published web app causes error when creating a directory

Posted on 2013-12-08
6
319 Views
Last Modified: 2013-12-09
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

    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

Open in new window

0
Comment
Question by:Soluga
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 4

Expert Comment

by:ShareD_Point
ID: 39704623
Hi,

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.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 39704629
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)
0
 
LVL 1

Author Comment

by:Soluga
ID: 39705771
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\CompanyMediaPublished\141a9a54-a3ab-440f-91c1-38eb16310b26\D60841BA-240C-468D-9B1A-02887F6FBEDE

  Dim source As New DirectoryInfo(Server.MapPath("../" & directorySource))
Line 83:         Dim destination As New DirectoryInfo(Server.MapPath("../" & directoryDestination))

Open in new window

0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 1

Author Comment

by:Soluga
ID: 39705907
I think the problem maybe because the code being executed is in my BL and should be in the UI layer
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 39705953
But the ".." part is parent path syntax, which is disabled by default in IIS. So I would still check that first. Which logical layer of you app is making the call won't make any difference.
0
 
LVL 1

Author Closing Comment

by:Soluga
ID: 39706304
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(HttpRuntime.AppDomainAppPath, directorySource))
        Dim destination As New DirectoryInfo(Path.Combine(HttpRuntime.AppDomainAppPath, directoryDestination))

This finally works.
3 days!! feck.

Thanks for your help.
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question