Home > Software engineering >  How to get a Subfolder with the SMBLibrary in .Net Core?
How to get a Subfolder with the SMBLibrary in .Net Core?

Time:12-21

So I need to acces a subfolder in Sharedrive with the SMBLibrary. I was expecting a list of folders of the subfolder but I always get a 0 count.

SMB2Client client = new SMB2Client();

bool isConnected = client.Connect("myServername", SMBTransportType.DirectTCPTransport);
if (isConnected)
{
    NTStatus status = client.Login(String.Empty, "user", "password");
    if (status == NTStatus.STATUS_SUCCESS)
    {
        List<string> shares = client.ListShares(out status);

        ISMBFileStore fileStore = client.TreeConnect("ShareName", out status);

        object directoryHandle;
        FileStatus fileStatus;
        string folder = @"ShareName/SUBFOLDER";

        status = fileStore.CreateFile(out directoryHandle, out fileStatus, folder, AccessMask.GENERIC_READ, FileAttributes.Directory, ShareAccess.Read | ShareAccess.Write, CreateDisposition.FILE_OPEN, CreateOptions.FILE_DIRECTORY_FILE, null);

         if(status == NTStatus.STATUS_SUCCESS)
         {
              List<QueryDirectoryFileInformation> fileList;
              status = fileStore.QueryDirectory(out fileList, directoryHandle, @"*", FileInformationClass.FileDirectoryInformation);
              status = fileStore.CloseFile(directoryHandle);
         }
         status = fileStore.Disconnect();
         client.Logoff();
      }
      client.Disconnect();
}

CodePudding user response:

after you perform TreeConnect to connect to a share, you shouldn't specify the share name when operating on that share. In your example, you perform CreateFile and including the ShareName which is incorrect.

  • Related