locked
Creating sub directories on the local storage RRS feed

  • Question

  • I tried creating sub directories on the local storage but it didn't work.

     

    Here is my code:

     

    LocalResource myLocalStorage = RoleEnvironment.GetLocalResource("LocalStorage");
    
    string filename = "data/testData.txt"
    string filepath = Path.Combine(myLocalStorage.RootPath, filename);
    
    StreamWriter qwe = File.CreateText(filepath);
    
    qwe.Write("testdata");
    
    text = File.ReadAllText(filepath);
    
    display (text);
    
    
    

    the program didn't display anything... It is as if hanged... 

     

    but this code did work

    LocalResource myLocalStorage = RoleEnvironment.GetLocalResource("LocalStorage");
    
    string filename = "testData.txt"
    string filepath = Path.Combine(myLocalStorage.RootPath, filename);
    
    StreamWriter qwe = File.CreateText(filepath);
    
    qwe.Write("testdata");
    
    text = File.ReadAllText(filepath);
    
    display (text);
    

    I thought it is some error in my code and I tried debugging locally on my machine and I got this exception

    DirectoryNotFoundException was unhandled

     

    Can anyone tell me how to create sub directories on the local storage... 

     

    Monday, February 21, 2011 7:55 AM

Answers

  • Don't you need to create the directory first?  Directory.CreateDirectory(Path.GetDirectoryName(filepath)) should do the trick. (I believe your code would fail in a regular console application too.)

    • Marked as answer by veda87 Monday, February 21, 2011 8:19 AM
    Monday, February 21, 2011 8:09 AM