• Upgrade your Internet Experience
  • Sign in
  • Microsoft.com
  • United States (English)
    Brasil (Português)Česká republika (Čeština)Deutschland (Deutsch)España (Español)France (Français)Italia (Italiano)Россия (Русский)대한민국 (한국어)中华人民共和国 (中文)台灣 (中文)日本 (日本語)香港特别行政區 (中文)
 
 
.NET Framework Developer Center
 
 
Home
 
 
Library
 
 
Learn
 
 
Downloads
 
 
Support
 
 
Community
 
 
Forums
 
 
 
.NET Framework Developer Center > .NET Development Forums > .NET Base Class Library > Passing a server path into DirectoryInfo
Ask a questionAsk a question
Search Forums:
  • Search .NET Base Class Library Forum Search .NET Base Class Library Forum
  • Search All .NET Development Forums Search All .NET Development Forums
  • Search All MSDN Forums Search All MSDN Forums
 

AnswerPassing a server path into DirectoryInfo

  • Wednesday, October 10, 2007 5:37 PMdotnetmate Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

    Hello Everyone,

    I am struck with something related to the server  path. I am trying to give a server path into the DirectoryInfo(), but it is taking the local directory path and saying that the path specified is not found. So can someone help me out in doing this.

    Thank you in Advance.

    your dotnetmate.

    • ReplyReply
    • QuoteQuote
     

Answers

  • Wednesday, October 10, 2007 6:16 PMnobugzMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Vote As Helpful
    0
    You are confusing variable names and string constants.  new DirectoryInfo(sou) for one.  Move the "sou" declaration out of the if statement.  An introductory book on C# programming would be highly advisable.
    • ReplyReply
    • QuoteQuote
     
  • Wednesday, October 10, 2007 7:23 PMdotnetmate Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Vote As Helpful
    0

    Thank you very much, I figured it out the mistake I am  doing, but still trying to solve it.

    • ReplyReply
    • QuoteQuote
     

All Replies

  • Wednesday, October 10, 2007 5:53 PMnobugzMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0
    Be sure to use the UNC name, \\server\share\etc.  Post your code if that's not it.
    • ReplyReply
    • QuoteQuote
     
  • Wednesday, October 10, 2007 6:03 PMdotnetmate Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

    This is my code I want to take the source path from the xml node and give it into the DirectoryInfo which will be copied to destination  in the same way.

     

    foreach (XmlNode node in nodesIdea)

    {

    String name = node.Name;

    if (name == "Source")

    {

    DirectoryInfo source = new DirectoryInfo(node.InnerText);

    String sou = node.InnerText.ToString();

    }

    else

    {

    String des = node.InnerText;

    }

    DirectoryInfo dir = new DirectoryInfo("Source");

    FileInfo[] f = dir.GetFiles("*");

    foreach (FileInfo file in dir.GetFiles("*"))

    {

    File.Copy(file.FullName,"des" + file.FullName.Substring(3), true);

    }

    DirectoryInfo dir1 = new DirectoryInfo("\\sou");

    DirectoryInfo[] dirs = dir1.GetDirectories();

    foreach (DirectoryInfo d in dirs)

    {

    if (!Directory.Exists("des" + d.Name))

    Directory.CreateDirectory("des" + d.Name);

    }

     

    Thanks.
    • ReplyReply
    • QuoteQuote
     
Need Help with Forums? (FAQ)
 
© 2009 Microsoft Corporation. All rights reserved.
Terms of Use
|
Trademarks
|
Privacy Statement