Access a shared folder(which is protected)

非 Y 不嫁゛ 提交于 2019-12-12 15:25:29

问题


I need help in writing a C# script which can access a secured shared location(i hv the username and password) in order to access some files from that location and also dump some files over there pragmatically. Thank you in advance


回答1:


To access a network share that is protected you need to call LogonUser and do impersonation within your application. The MSDN article provides a code sample. Then you can just browse, copy/move, etc with the System.IO namespace. For instance:

System.IO.Directory.GetFolders(@"\\Server\Share");

will return a list of the folders on the network share.




回答2:


I take it the app will be running under credentials different than the username/password that can access the folder.

You can use impersonation, see this question for how to set up the win32 api calls to logon and revert to self.

Impersonate user in codebehind



来源:https://stackoverflow.com/questions/4661248/access-a-shared-folderwhich-is-protected

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!