WNetAddConnection2 Remote Access and read the directory files in c# -


i have read file "abc.txt" content remote server on intranet. used wnetaddconnection2 that. used stackoverflow link , this link too. made connection success. when try use remote connection still points c drive. want connection use remote 1 made , files there.

var onc = new system.net.networkcredential()                       {                           domain = "192.1.x.y",                           username = "localhost\\myremoteadminusername",                           password = "myremotepassword"                       };         using (new networkconnection(@"\\" + "192.1.x.y", onc))         {             string[] sfoldernames = directory.getdirectories(onc.domain + "\\logs"); //get exception in above line bcoz somehow points local c:\...\\bin\debug\192.1.x.y\logs  //instead of remote 192.1.x.y\logs              foreach (string sfoldername in sfoldernames)              {                 string[] sarrzipfiles = directory.getfiles(sfoldername, "*.txt");                  foreach (string sfile in sarrzipfiles)                  {                   }             }          } 

what doing wrong? let me know if need else.

this code vc++, works getting access remote resources. might  #include "stdafx.h" #ifndef unicode #define unicode #endif #pragma comment(lib, "mpr.lib")  #include <windows.h> #include <tchar.h> #include <stdio.h> #include <winnetwk.h> #include<iostream> #include<string>  // need link netapi32.lib , mpr.lib int _tmain(int argc, _tchar* argv[]){   dword dwretval;     netresource nr; dword dwflags;   dword cancelretval;  // 0 out netresource struct memset(&nr, 0, sizeof(netresource));  // assign our values netresource structure.    nr.dwtype = resourcetype_any;  nr.dwscope = resource_globalnet; nr.lplocalname =null;  nr.lpremotename = l"\\\\x.x.x.x\\folder";  nr.lpprovider = null;  // assign value connection options dwflags = connect_update_profile;     cancelretval = wnetcancelconnection2(l"\\\\x.x.x.x\\fodler", 0, true);  //usage wnetaddconnection2("location", l"password", l"domain\\username", 0); dwretval = wnetaddconnection2(&nr, l"password", l"domain\\username", 0);  if (dwretval == no_error)     wprintf(l"connection added %s\n", nr.lpremotename); else     wprintf(l"wnetaddconnection2 failed error: %u\n", dwretval);  std::string s; std::getline(std::cin, s); exit(1); 

}


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo