VB.Net File.Copy/File.Move with different credentials

只愿长相守 提交于 2019-12-22 14:08:45

问题


Ideally I'd like to be able to copy/move between an accessible folder on my local drive and a network share that I don't have permission to access (but the application would).

I am using impersonation to give me access to the files in the network share but using System.IO File.Move or File.Copy forces me to use the same credentials for each location. Is there a way around this?


回答1:


What I believe you could do is something like this.

  1. Do the impersonation to allow the selection of files. Copy the files to a location that the app can get to.
  2. Stop the impersonation then have the application copy the file from the temp location to the desired end result.

We have done this before in our applications, it isn't elegant, but it works perfectly!




回答2:


We've done something similar to what Mitchel Sellers is doing, except that we don't have a location that both identities can read from. We are reading blocks of data into memory using the local context and writing them out while impersonating the remote user.



来源:https://stackoverflow.com/questions/710186/vb-net-file-copy-file-move-with-different-credentials

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