c# - Uploading files to file server using webclient class -


currently have application receives uploaded file web application. need transfer file file server happens located on same network (however might not case).

i attempting use webclient class in c# .net.

    string filepath = "c:\\test\\564.flv";     try     {         webclient client = new webclient();          networkcredential nc = new networkcredential(uname, password);          uri addy = new uri("\\\\192.168.1.28\\files\\test.flv");         client.credentials = nc;         byte[] arrreturn = client.uploadfile(addy, filepath);         console.writeline(arrreturn.tostring());     }     catch (exception ex)     {         console.writeline(ex.message);     } 

the machine located @ 192.168.1.28 file server , has share c:\files. of right receiving error of login failed bad user name or password, can open explorer , type in path login successfully. can login using remote desktop, know user account works.

any ideas on error? possible transfer file directly that? webclient class or maybe other class?

just use

file.copy(filepath, "\\\\192.168.1.28\\files"); 

a windows fileshare exposed via unc path treated part of file system, , has nothing web.

the credentials used of asp.net worker process, or impersonation you've enabled. if can tweak right, can done.

you may run problems because using ip address instead of server name (windows trust settings prevent leaving domain - using ip hiding domain details). if @ possible, use server name!

if not on same windows domain, , trying use different domain account, need specify username "[domain_or_machine]\[username]"

if need specify explicit credentials, you'll need coding impersonation solution.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -