Accessing LAN from the page through Web Service

  • Thread starter Thread starter JP
  • Start date Start date
J

JP

Hi,

I want to import a few Excel Sheets from a network drive
(e.g. F:\, some file server). The way it works right now
is I have a 'File Watcher' that picks up the files as soon
as they are available and dumps them into the Web Server
and then the Web Service 'File Importer' on the same Web
Server imports them into the database.

I would like to trigger the import with a 'Click' event
and without the 'File Watcher' moving the files into the
Web Server. The problem I am having with this is to supply
the credentials from the 'Click' event and connect to that
network drive (F:\, the file server) through the Web
Server using the Web Service 'File Importer'.

How do I connect to this network drive through the Web
Service by supplying the credentials from the web page?

Thanks in advance!
Regards,
JP
 
I've used this (complete code) and it works well for this sort of thing. It
maps a null drive to \\server\ipc$ hope this helps..

using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential)]
public struct NETRESOURCEA
{
public int dwScope;
public int dwType;
public int dwDisplayType;
public int dwUsage;
[ MarshalAs (UnmanagedType.LPStr)]
public string lpLocalName;
[ MarshalAs (UnmanagedType.LPStr)]
public string lpRemoteName;
[ MarshalAs (UnmanagedType.LPStr)]
public string lpComment;
[ MarshalAs (UnmanagedType.LPStr)]
public string lpProvider;
public override String ToString()
{
String str = "LocalName: " + lpLocalName + " RemoteName: " + lpRemoteName
+ " Comment: " + lpComment + " lpProvider: " + lpProvider;
return(str);
}
}

class Authentication
{
[DllImport("mpr.dll")]
private static extern int WNetAddConnection2A(
[MarshalAs(UnmanagedType.LPArray)] NETRESOURCEA[] lpNetResource,
[MarshalAs(UnmanagedType.LPStr)] string lpPassword,
[MarshalAs(UnmanagedType.LPStr)] string UserName,
int dwFlags);
[DllImport("mpr.dll")]
private static extern int WNetCancelConnection2(
[MarshalAs(UnmanagedType.LPStr)] string lpName,
int dwFlags,
bool fForce);

public static int ValidateUser(string Server,string User,string Password)
{
NETRESOURCEA [] n = new NETRESOURCEA[1];
n[0] = new NETRESOURCEA();
n[0].dwType = 0;
int dwFlags = 1;
n[0].lpLocalName = null;
n[0].lpRemoteName = @"\\" + Server + @"\IPC$";
n[0].lpProvider = null;

int res = WNetAddConnection2A( n, Password, User, dwFlags );
return res;
}
public static void CancelConnection(string Connection)
{
WNetCancelConnection2(Connection, 0, true);
}
}
 
Back
Top