Here is the code i am using (from ASP.NET) to access shared folder. You
obviously must have User/Password to access that folder.
#region WIN API Declarations
//used in calling WNetAddConnecti on2
[StructLayout(La youtKind.Sequen tial)]
public struct NETRESOURCE
{
public int dwScope;
public int dwType;
public int dwDisplayType;
public int dwUsage;
[MarshalAs(Unman agedType.LPStr)]
public string lpLocalName;
[MarshalAs(Unman agedType.LPStr)]
public string lpRemoteName;
[MarshalAs(Unman agedType.LPStr)]
public string lpComment;
[MarshalAs(Unman agedType.LPStr)]
public string lpProvider;
}
//WIN32API - WNetAddConnecti on2
[DllImport("mpr. dll",
CharSet = System.Runtime. InteropServices .CharSet.Auto)]
private static extern int WNetAddConnecti on2A(
[MarshalAs(Unman agedType.LPArra y)] NETRESOURCE[] lpNetResource,
[MarshalAs(Unman agedType.LPStr)] string lpPassword,
[MarshalAs(Unman agedType.LPStr)] string lpUserName,
int dwFlags);
[DllImport("mpr. dll",
CharSet = System.Runtime. InteropServices .CharSet.Auto)]
private static extern int WNetCancelConne ction2A(
[MarshalAs(Unman agedType.LPStr)] string lpName,
int dwFlags, int fForce);
#endregion
private byte[] GetFSMSFile(str ing sFile)
{
NETRESOURCE[] nr = new NETRESOURCE[1];
nr[0].lpRemoteName = _sFSMSShare;
nr[0].lpLocalName = ""; //mLocalName;
nr[0].dwType = 1; //disk
nr[0].dwDisplayType = 0;
nr[0].dwScope = 0;
nr[0].dwUsage = 0;
nr[0].lpComment = "";
nr[0].lpProvider = "";
int iErr = WNetAddConnecti on2A(nr, _sFSMSShareUser Password,
_sFSMSShareUser , 0);
if (iErr 0)
throw new Exception("Can not connect to FSMS share folder");
FileStream st = null;
try
{
st = new FileStream(_sFS MSShare + "\\" + sFile,
FileMode.Open);
int iLen = (int)st.Length;
byte []b = new byte[iLen];
st.Read(b, 0, iLen);
return b;
}
finally
{
if( st != null )
st.Close();
WNetCancelConne ction2A(_sFSMSS hare, 0, -1);
}
}
George
"sloan" <sl***@ipass.ne twrote in message
news:%2******** **********@TK2M SFTNGP03.phx.gb l...
>
You should always know "who" is running the code.
LocalMachine\AS PNET account is typical.
Thus this account would need permissions to read the files on the file
server.
OR you can do impersonation as you see.
Here is some crappy code to ID the account running........ ....
Don't assume, check it when you don't know.
private string FindIIdentity()
{
try
{
//'Dim user As WindowsPrincipa l =
CType(System.Th reading.Thread. CurrentPrincipa l, WindowsPrincipa l)
//'Dim ident As IIdentity = user.Identity
string returnValue = string.Empty;
WindowsIdentity ident = WindowsIdentity .GetCurrent();
returnValue = ident.Name;
try
{
returnValue += " on " + System.Environm ent.MachineName ;
}
catch (Exception ex)
{
Console.WriteLi ne(ex.Message);
}
return returnValue;
}
catch (Exception ex)
{
Conditionals.Tr ace.WriteMessag e(ex.Message);
return "Error Finding Identity";
}
}
"JeffP->" <Je***@discussi ons.microsoft.c omwrote in message
news:E2******** *************** ***********@mic rosoft.com...
>>I want to retrieve an image file (TIF) convert it to a bmp file and enable
sizing.
I know how to do the converting & sizing part, and store any atributes to
file location in the webconfig, what I don't know is how to get the image
file.
The only way that I've got it working was to Impersonate a user login at
the
other server.
Potential clues...
Image.FromFi le
Server.MapPa th
URL
Any links or similar are appreciated.