Click here to Skip to main content
15,613,470 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to transfer folder from server to client machine.I have a web application in which i need to transfer folder(which contains multiple file) on client machine on button click.I cannot use exe or anything else on client side. This is my project requirement. Its just like a website which user opens in his/her browser and then click on a button which will transfer folder on client machine silently. I have also tried http headers option in which it will open dialog box which will ask for path where i want to save a folder.I also tried windows impersation using win32 API using that i have successfully created folder on client machine and then transfer files from server to client machine. In this case i have IP address, administrator userid and password of the client machine but this case fail when user's machine shifted on domain, then due to policies file and printer sharing for microsoft networks network protocol checkbox unchecked. Because of this my code cannot create connection with client machine although it have administrator id and password but it give error "network path not found". If manually we will check file and printer sharing for microsoft networks on client machine then code will run successfully.That's why know i want to transfer folder using tcp port in c#.
If anyone have any solution please help on priority basis. I am stuck in this problem more than 10 days but still not foun any solution. I have checked lot of code on google and it shows me one more option socket programming but iam unable to achieve it. Please give me solution its urgent.
Michael dg 16-Feb-12 8:48am    
Is the web server and your client machine(target folder) are accessible? I mean does the web server can access the client/target machine?
Michael dg 16-Feb-12 8:51am    
Correct me if I am wrong,
1. User click the upload/sync button.
2. Webserver copy the files to the target machine. The target folder must be a shared folder.

Member 7979150 17-Feb-12 1:14am    
Thanks for reply.
if file and printer sharing for microsoft network(network protocol) is unchecked then in that case i cannot access client machine otherwise it is accessible.
please find my code below:-

public void CreateDir(string DriverPath)
IntPtr token = IntPtr.Zero;

WindowsImpersonationContext impersonatedUser = null;
Hashtable Fod_Files = new Hashtable();

// Create a token for DomainName\UserName

//Call LogonUser function to obtain an access token
// for the specified user

client_Uname = "a1093557";
// client_IPAddress = "";
client_pwd = "sairam@9";
DomainName = "";

bool result = LogonUser(client_Uname, DomainName,
out token);

if (result)
//create a new window identity from the window access token

WindowsIdentity id = new WindowsIdentity(token);

// Begin impersonation

impersonatedUser = id.Impersonate();

Drv_FolderPath = @"C:\PrntDriver1";
DriverPath = @"\\\C$\hp";

if (Directory.Exists(Drv_FolderPath))

// Drv_FolderPath = @"\\" + client_IPAddress + @"\C$\PrntDriver";


Fod_Files = Chk_Files(DriverPath);

string[] FileName = null;

string[] Drv_Fold = null;

Drv_Fold = DriverPath.Split('\\');
int i = Drv_Fold.Length;
//loop on hashtable which contains all the file with their path
foreach (string f in Fod_Files.Values)
FileName = f.Split('\\');

string Dest_Path = Drv_FolderPath + @"\" + FileName[i];

if (!File.Exists(Dest_Path))
//it will copy files on client machine
System.IO.File.Copy(f, Dest_Path);


// utl.putLogData(DateTime.Now.ToString() + " Driver setup copied successfully ");

// if the LogonUser return code is zero,an error has occured

// utl.putLogData("</p>LogonUser failed: " +
// Marshal.GetLastWin32Error().ToString());
//Response.Write("</p>LogonUser failed: " +

catch (Exception ex)


// Stop impersonation and revert to the process identity
if (impersonatedUser != null)
//// Free the token
if (token != IntPtr.Zero)

Member 7979150 17-Feb-12 1:18am    
I mean file and printer sharing for microsoft networks(network protocol) unchecked on client m/c then server cannot access client machine it will show error "network path not found". even if i access client m/c through run from server it will show same error which it shows through code. Please give me solution. I will be grateful for this. It's very urgent and iam stuck in this more than 10 days. please .............. help me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900