Accessing Shared Folder through C#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chandra Sekhar

    #1

    Accessing Shared Folder through C#

    I want to access a shared folder of a different machine (Mapped to my
    server) say E:\ (which is actually \\myothermac\c$ \somefolder") from C#.

    If I use
    string strFolder = "E:\myNewFolder ";
    if (System.IO.Dire ctory.Exists(st rFolder))
    { ... }
    it always says the directory doesn't exist. I thought it might be
    something to do with security and I enabled everyone to have full access
    on the other machine. But it didnt help.

    I know ASPNET user will not know the share created by any other user on
    the machine, but how do you suggest me do it?

    I even tried this:
    string strFolder = "\\\\MyOtherMac hine\\c$\\myNew Folder";
    if (System.IO.Dire ctory.Exists(st rFolder))
    { ... }


    Could you please help me in solving this issue?

    Thanks in advance.

    Sekhar.

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • Chris Capel

    #2
    Re: Accessing Shared Folder through C#

    C$ is a system share, so it's treated differently than the normal shares.
    You should probably make a different share (maybe one that doesn't start at
    the root directory) and use that one. Maybe that'll help.

    Chris

    "Chandra Sekhar" <mail@sekhar.ne t> wrote in message
    news:uTZgfs8TDH A.2252@TK2MSFTN GP12.phx.gbl...[color=blue]
    > I want to access a shared folder of a different machine (Mapped to my
    > server) say E:\ (which is actually \\myothermac\c$ \somefolder") from C#.
    >
    > If I use
    > string strFolder = "E:\myNewFolder ";
    > if (System.IO.Dire ctory.Exists(st rFolder))
    > { ... }
    > it always says the directory doesn't exist. I thought it might be
    > something to do with security and I enabled everyone to have full access
    > on the other machine. But it didnt help.
    >
    > I know ASPNET user will not know the share created by any other user on
    > the machine, but how do you suggest me do it?
    >
    > I even tried this:
    > string strFolder = "\\\\MyOtherMac hine\\c$\\myNew Folder";
    > if (System.IO.Dire ctory.Exists(st rFolder))
    > { ... }
    >
    >
    > Could you please help me in solving this issue?
    >
    > Thanks in advance.
    >
    > Sekhar.
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it![/color]


    Comment

    • Scott

      #3
      Re: Accessing Shared Folder through C#

      I have a program which searches our network.
      This runs off a fileshare path (well a database of root
      paths in my case) in the form of \\server\sharen ame

      I do it like this...

      private bool CheckPath(strin g sPath)
      {
      DirectoryInfo objDir = new DirectoryInfo(s Path);

      //Check if its real!
      if(objDir.Exist s)
      {
      //find all directories
      DirectoryInfo[] objSubDirs = objDir.GetDirec tories();

      //recurse each directory
      for(int i = 0;i<objSubDirs. Length; i++)
      {
      CheckPath(objSu bDirs[i].FullName);
      }

      //Do more stuff here
      }


      [color=blue]
      >-----Original Message-----
      >C$ is a system share, so it's treated differently than[/color]
      the normal shares.[color=blue]
      >You should probably make a different share (maybe one[/color]
      that doesn't start at[color=blue]
      >the root directory) and use that one. Maybe that'll help.
      >
      >Chris
      >
      >"Chandra Sekhar" <mail@sekhar.ne t> wrote in message
      >news:uTZgfs8TD HA.2252@TK2MSFT NGP12.phx.gbl.. .[color=green]
      >> I want to access a shared folder of a different machine[/color][/color]
      (Mapped to my[color=blue][color=green]
      >> server) say E:\ (which is actually[/color][/color]
      \\myothermac\c$ \somefolder") from C#.[color=blue][color=green]
      >>
      >> If I use
      >> string strFolder = "E:\myNewFolder ";
      >> if (System.IO.Dire ctory.Exists(st rFolder))
      >> { ... }
      >> it always says the directory doesn't exist. I thought[/color][/color]
      it might be[color=blue][color=green]
      >> something to do with security and I enabled everyone to[/color][/color]
      have full access[color=blue][color=green]
      >> on the other machine. But it didnt help.
      >>
      >> I know ASPNET user will not know the share created by[/color][/color]
      any other user on[color=blue][color=green]
      >> the machine, but how do you suggest me do it?
      >>
      >> I even tried this:
      >> string strFolder[/color][/color]
      = "\\\\MyOtherMac hine\\c$\\myNew Folder";[color=blue][color=green]
      >> if (System.IO.Dire ctory.Exists(st rFolder))
      >> { ... }
      >>
      >>
      >> Could you please help me in solving this issue?
      >>
      >> Thanks in advance.
      >>
      >> Sekhar.
      >>
      >> *** Sent via Developersdex http://www.developersdex.com[/color][/color]
      ***[color=blue][color=green]
      >> Don't just participate in USENET...get rewarded for it![/color]
      >
      >
      >.
      >[/color]

      Comment

      Working...