Forum Moderators: open

Message Too Old, No Replies

Cannot create Directory on Remote Server (ASP.NET)

         

pedrodepacos

4:37 am on Oct 16, 2003 (gmt 0)

10+ Year Member



Hello,

I need my ASP.NET application to create and delete directories. I have asked my hosting provider to setup a public folder that is has its permissions set to read/write. I know that this public folder has these permissions because my application can create and delete files inside this directory. My problem is that when I try to create a directory inside this public folder, I get the following error...

System.IO.FileNotFoundException: Could not find file "D:\folder\example.com\html\public\test".

This is the code that I've been using (and it has been working perfectly on my development machine)...

 
Dim strDir As String = "D:\folder\example.com\html\public\test"
Dim dir As New System.IO.DirectoryInfo(strDir)
If dir.Exists = False Then
'create the directory
dir.Attributes = IO.FileAttributes.Directory
dir.Create()
End If

I've been told by my hosting provider that everything is set properly on their end, but I don't know what else could be giving me the error. When I create the directory through ftp then dir.Exists = True so I know that I have the correct path the my public folder.

Please, if anyone has any suggestions I'd be grateful if you could share them with me. I don't know whether or not my hosting provider is actually to blame or if I need to modify my code. I've been trying to resolve this for 2 days and between my and my provider, we've still yet to come up with a solution.

[edited by: engine at 2:06 pm (utc) on Oct. 16, 2003]
[edit reason] widgetised [/edit]

IanTurner

8:19 am on Oct 16, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



You should ensure that both the ASP.Net user and IUSR accounts have modify permission on the parent folder where the new directory is being created.

pedrodepacos

8:37 am on Oct 16, 2003 (gmt 0)

10+ Year Member



Thanks, however, the director did have modify permission and it still gave me the error. After much wasted time, I realized that I could just use the FileSystemObject to create, delete and move the directories and now everything is working fine. I guess that I should still try to incorporate Classic ASP when I can't do something in .NET

aspdaddy

8:51 am on Oct 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>Dim dir As New System.IO.DirectoryInfo(strDir)

I dont know any .net, but I would guess that when you use that constructor , it simply allocates the memory - so expects an existing directory as the parameter.

pedrodepacos

5:23 pm on Oct 17, 2003 (gmt 0)

10+ Year Member



I also tried System.IO.Directory.CreateDirectory(strDir) and this also did not work. I don't think that it is a problem with the actual code. My Hosting Provider told me that the security settings would have to be changed in order for me to create directories using ASP.NET. They are not willing to do that so I'm just using the FileSystemObject and it works fine now.

korkus2000

5:38 pm on Oct 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code is fine. It is a permissions issue. I think your workaround is probably best considering your host's stance on the issue.

swanseajack

8:41 pm on Oct 27, 2003 (gmt 0)



The account used to process your requests probably does not have any permissions on the root of the drive (d:\ in your case). I had a similar problem. Security auditing showed that the account was trying to access the root drive for ReadAttributes access whenever the Create method of the DirectoryInfo class was used. The Advanced dialog box available from the Security tab (accessed from the folder properties dialog) allows an administrator to give the account ReadAttributes permissions only.

DW_Warlock

12:01 am on Oct 28, 2003 (gmt 0)

10+ Year Member



It is definatly a permissions issue... take this code for instance..

private void CreateDirectory(string path)
{
try
{
DirectoryInfo di = new DirectoryInfo(path);
if(di == null)
{
di.Create();
}
}
catch(Exception ex)
{
Response.Write(ex);
}
}

On a local machine, it should execute just fine if the ASP.NET process has read/write permissions both in the NTFS file system and also in IIS. If both are not in sync, then the opertaion will fail.

Also, try using try..catch blocks to see if it is a permissions issue or if the directory exists already. Chances are, the host did not setup the virtual directory in IIS to be read/write and/or did not set the proper permissions on the local folder.

HTH,
Bill P.

pedrodepacos

12:19 am on Oct 28, 2003 (gmt 0)

10+ Year Member



Thanks everyone for your input. I agree that it is a permission issue but with my hosting provider not really willing to explore this issue further, I think my workaround of using the FileSystemObject is the best solution for this situation.