Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Directory.CreateDirectory

Reply
 
Old 07-09-2008   #1 (permalink)
Tom


 
 

Directory.CreateDirectory

This is really weird, but I have the following code:

private static readonly string mString = "tempUnzipDir" +
Path.DirectorySeparatorChar;

....

public static string ExtractToTempLocation(string aZip)
{
try
{
string tmp = Path.GetTempPath() + mString;
Directory.CreateDirectory(tmp);
// Extract the zip file
}
catch(Exception e)
{
}
}

The code above creates a temporary directory fine on my dev machine (Vista),
but will not create a temp directory on my server (server 2K3 R2) when I
move the code over the to server. I have some logging enabled that isn't
shown in the code above, and it is definately pointing to the correct
location of the temp directory to be created. Even more weird is that the
call to Directory.CreateDirectory(tmp); does not throw any type of exception
on the server. It just keeps executing as if it worked correctly. Does
anybody have any ideas why this isn't working?

Thanks.


My System SpecsSystem Spec
Old 07-09-2008   #2 (permalink)
Tom


 
 

Re: Directory.CreateDirectory

Even more weird, if I change the code to this:
private static readonly string mString = "tempUnzipDir" +
Path.DirectorySeparatorChar + "anotherDir" + Path.DirectorySeparatorChar;

....

public static string ExtractToTempLocation(string aZip)
{
try
{
string tmp = Path.GetTempPath() + mString;
Directory.CreateDirectory(tmp);
// Extract the zip file
}
catch(Exception e)
{
}
}

I see the directory "tempUnzipDir" get created under the administrator's
temporary directory. However, the directory [administrator's temp
path]\tempUnzipDir\anotherDir does not get created. WTH??!!!



"Tom" <johnthompson1@xxxxxx> wrote in message
news:BDD91C65-40DD-433F-8932-18E1A089EE12@xxxxxx
Quote:

> This is really weird, but I have the following code:
>
> private static readonly string mString = "tempUnzipDir" +
> Path.DirectorySeparatorChar;
>
> ...
>
> public static string ExtractToTempLocation(string aZip)
> {
> try
> {
> string tmp = Path.GetTempPath() + mString;
> Directory.CreateDirectory(tmp);
> // Extract the zip file
> }
> catch(Exception e)
> {
> }
> }
>
> The code above creates a temporary directory fine on my dev machine
> (Vista), but will not create a temp directory on my server (server 2K3 R2)
> when I move the code over the to server. I have some logging enabled that
> isn't shown in the code above, and it is definately pointing to the
> correct location of the temp directory to be created. Even more weird is
> that the call to Directory.CreateDirectory(tmp); does not throw any type
> of exception on the server. It just keeps executing as if it worked
> correctly. Does anybody have any ideas why this isn't working?
>
> Thanks.
>
My System SpecsSystem Spec
Old 07-09-2008   #3 (permalink)
Norman Yuan


 
 

Re: Directory.CreateDirectory

What type of application are you doing? When you say move code to "server",
does that mean a ASP.NET application, a Windows service application or a
desktop application? Without knowing which user account is used to run your
app, it is hard to tell what is wrong. But it ceratinly sounds like you have
permission problem. As for the code not throwing exception, if the code you
show is the real code, then of course the code does throw exception and is
caught in catch(){} block. However, since you did nothng in the "catch..."
block, the code continues. That is, if you use try...catch... and do nothing
when exception ia caught, that is equal to ignorig the exception and the
code would continue counting on your luck to finish.

"Tom" <johnthompson1@xxxxxx> wrote in message
news:BDD91C65-40DD-433F-8932-18E1A089EE12@xxxxxx
Quote:

> This is really weird, but I have the following code:
>
> private static readonly string mString = "tempUnzipDir" +
> Path.DirectorySeparatorChar;
>
> ...
>
> public static string ExtractToTempLocation(string aZip)
> {
> try
> {
> string tmp = Path.GetTempPath() + mString;
> Directory.CreateDirectory(tmp);
> // Extract the zip file
> }
> catch(Exception e)
> {
> }
> }
>
> The code above creates a temporary directory fine on my dev machine
> (Vista), but will not create a temp directory on my server (server 2K3 R2)
> when I move the code over the to server. I have some logging enabled that
> isn't shown in the code above, and it is definately pointing to the
> correct location of the temp directory to be created. Even more weird is
> that the call to Directory.CreateDirectory(tmp); does not throw any type
> of exception on the server. It just keeps executing as if it worked
> correctly. Does anybody have any ideas why this isn't working?
>
> Thanks.
>
My System SpecsSystem Spec
Old 07-09-2008   #4 (permalink)
Tom


 
 

Re: Directory.CreateDirectory

I found the problem. It was a sync issue. This was a plug-in for a Windows
service. Another plug-in was deleting temp directories.

Sorry to bug everyone.


"Norman Yuan" <FakeName@xxxxxx> wrote in message
news:eRMWP2e4IHA.3480@xxxxxx
Quote:

> What type of application are you doing? When you say move code to
> "server", does that mean a ASP.NET application, a Windows service
> application or a desktop application? Without knowing which user account
> is used to run your app, it is hard to tell what is wrong. But it
> ceratinly sounds like you have permission problem. As for the code not
> throwing exception, if the code you show is the real code, then of course
> the code does throw exception and is caught in catch(){} block. However,
> since you did nothng in the "catch..." block, the code continues. That is,
> if you use try...catch... and do nothing when exception ia caught, that is
> equal to ignorig the exception and the code would continue counting on
> your luck to finish.
>
> "Tom" <johnthompson1@xxxxxx> wrote in message
> news:BDD91C65-40DD-433F-8932-18E1A089EE12@xxxxxx
Quote:

>> This is really weird, but I have the following code:
>>
>> private static readonly string mString = "tempUnzipDir" +
>> Path.DirectorySeparatorChar;
>>
>> ...
>>
>> public static string ExtractToTempLocation(string aZip)
>> {
>> try
>> {
>> string tmp = Path.GetTempPath() + mString;
>> Directory.CreateDirectory(tmp);
>> // Extract the zip file
>> }
>> catch(Exception e)
>> {
>> }
>> }
>>
>> The code above creates a temporary directory fine on my dev machine
>> (Vista), but will not create a temp directory on my server (server 2K3
>> R2) when I move the code over the to server. I have some logging enabled
>> that isn't shown in the code above, and it is definately pointing to the
>> correct location of the temp directory to be created. Even more weird is
>> that the call to Directory.CreateDirectory(tmp); does not throw any type
>> of exception on the server. It just keeps executing as if it worked
>> correctly. Does anybody have any ideas why this isn't working?
>>
>> Thanks.
>>
>
My System SpecsSystem Spec
Old 07-26-2008   #5 (permalink)
tim


 
 

Re: Directory.CreateDirectory

Try using System.IO.Path.Combine() method instead of string concat.

"Tom" <johnthompson1@xxxxxx> wrote in message
news:61B35E73-2802-481A-BF57-5F1E87717663@xxxxxx
Quote:

> Even more weird, if I change the code to this:
> private static readonly string mString = "tempUnzipDir" +
> Path.DirectorySeparatorChar + "anotherDir" + Path.DirectorySeparatorChar;
>
> ...
>
> public static string ExtractToTempLocation(string aZip)
> {
> try
> {
> string tmp = Path.GetTempPath() + mString;
> Directory.CreateDirectory(tmp);
> // Extract the zip file
> }
> catch(Exception e)
> {
> }
> }
>
> I see the directory "tempUnzipDir" get created under the administrator's
> temporary directory. However, the directory [administrator's temp
> path]\tempUnzipDir\anotherDir does not get created. WTH??!!!
>
>
>
> "Tom" <johnthompson1@xxxxxx> wrote in message
> news:BDD91C65-40DD-433F-8932-18E1A089EE12@xxxxxx
Quote:

>> This is really weird, but I have the following code:
>>
>> private static readonly string mString = "tempUnzipDir" +
>> Path.DirectorySeparatorChar;
>>
>> ...
>>
>> public static string ExtractToTempLocation(string aZip)
>> {
>> try
>> {
>> string tmp = Path.GetTempPath() + mString;
>> Directory.CreateDirectory(tmp);
>> // Extract the zip file
>> }
>> catch(Exception e)
>> {
>> }
>> }
>>
>> The code above creates a temporary directory fine on my dev machine
>> (Vista), but will not create a temp directory on my server (server 2K3
>> R2) when I move the code over the to server. I have some logging enabled
>> that isn't shown in the code above, and it is definately pointing to the
>> correct location of the temp directory to be created. Even more weird is
>> that the call to Directory.CreateDirectory(tmp); does not throw any type
>> of exception on the server. It just keeps executing as if it worked
>> correctly. Does anybody have any ideas why this isn't working?
>>
>> Thanks.
>>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Do I need this Directory? Vista General
Setting up a directory and moving a file into that directory from Vista General
Setting up a directory and moving a file into that directory from Vista General
how do I keep powershells current directory and dotnets current directory in sync PowerShell
Temp Directory acts like media directory Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46