Refresh Mapped Drive Using C# Code RRS feed

  • Question

  • Hi,

    When my pc start and connect with network showing mapped drive with cross sign and that if i will use the mapped drive in our code,it will not be accessible ,if we will double click on that drive and again will be accessible. 

    so i want to know how to use in code behind same process which i am doing manually double click on drive.

    Friday, November 15, 2019 7:23 AM

All replies

  • You said code behind which makes me thing web app. What type of app do you have?

    .NET does not expose any functionality to manage mapped drives. To do that you'll need to P/Invoke to the Win32 calls. In general you shouldn't need mapped drives in an app. Just use the UNC path. The only reason for a mapped drive would be if the location could change outside your app in which case it should probably be a config entry. Irrelevant when you reference a mapped drive Windows should connect to it provided it was persisted (which is set when the drive is originally mapped).

    Please post the code that is having issues and the error message(s) you're getting. Also clarify why you cannot just use a UNC path instead.

    Michael Taylor

    Friday, November 15, 2019 3:11 PM