views:

20

answers:

1

I am trying to create an export feature for a user to be able to download documents into a zip file. I have the feature working when the files are located on my local and I can use an absolute path on my local. But after talking to the infrastructure team, I found out that the documents are not stored on the same machine as the web server but located at a server farm located off site. I can query the database which gives me a file path. But the path is more of a relative path.

So can anyone help me understand how to use FileInfo with getting files from another machine. I believe the infrastructure team said there is a virtual drive set up to the outside server. Am I able to use a virtual path some how? Thanks.

A: 

If the file is on your LAN or VPN you can use a UNC path.

Typically for UNC paths you will access a computer's file using it's administrative share like so:

\\ComputerName\c$

You can use all of the normal file io functions to work with UNC paths. If you can't access the computer because you need authentication then you should use the Win32 API WNetUseConnection via DllImport.

[DllImport("Mpr.dll")] private static extern int WNetUseConnection(
        IntPtr hwndOwner,
        NETRESOURCE lpNetResource,
        string lpPassword,
        string lpUserID,
        int dwFlags,
        string lpAccessName,
        string lpBufferSize,
        string lpResult
    );

If the file is located on some computer that is distinct from your network then you'll have to go through some kind of server such as FTP or HTTP which is hosted on the remote machine.

Brian R. Bondy
@Brian- Thanks man, I want to say it's a VPN. As soon as I can get the path for it I'll try it out and let you know if it works. Thanks for the advice.
jhorton