tags:

views:

411

answers:

2

I have created a web part which renders a button, on click of this button I want to access the directory of the other machine in LAN. Once I get the access to this Directory I will create a nested directories inside it with different extensions of files, but the problem is when I tries to access this folder by UNC Path it is giving me error like "Could not find a part of the path '\comp01\ibc'". Here comp01 is the computer name which is situated in LAN and ibc is a shared folder on that machine.

Following is the code for button click,

void _btnBackup_Click(object sender, EventArgs e)
{
    try
    {
     //UNC Path --> \\In-Wai-Svr2\IBC
     if (!string.IsNullOrEmpty(UncPath))
     {
      SPSite currentSite = SPControl.GetContextSite(this.Context);
      SPWeb parentWeb = currentSite.OpenWeb();

      string dir = Path.GetDirectoryName(UncPath);

      //If IBC folder does not exist then create it.
      if(!Directory.Exists(dir))
       Directory.CreateDirectory(dir);                    

      IterateThroughChildren(parentWeb, UncPath);
     }
     else
     {
      _lblMessage.Text = "UNC Path should not be empty";
     }
    }
    catch(Exception ex)
    {
     _lblMessage.Text = ex.Message;
    }
}
A: 

For UNC paths you need to specify it like this:

either use a C# string literal

String path = @"\\comp01\ibc";

or escape the string like

String path = "\\\\comp01\\ibc"

Try that.

Lee Dale
I did the same as specified by you. But then also its giving the error. If I add this web part to a web site on different wss server then it works fine.
Tejas
The only thing I can think of if this code works on another server is that the server that is throwing an error must not have visibility to the folder share on the LAN?Can you definitely ping the server and resolve the hostname from your WSS server?
Lee Dale
A: 

hi, Did you get hte solution for this? I am trying to do same thing. I want to access the files stored on a Shared folder (On unother pc in same domain) and read/delete those files. If I add the user in administrative group, it is working. But for the user who is not in admin group, it gives error. Can you help me out?

Change the security account of the Application Pool to from Predefined to Administrator
Tejas