Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Access network share from ASP.NET
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Yuriy Galanter  
View profile  
 More options Mar 10 2008, 3:50 pm
Newsgroups: microsoft.public.dotnet.framework.aspnet
From: "Yuriy Galanter" <y...@galanter.net>
Date: Mon, 10 Mar 2008 15:50:57 -0400
Local: Mon, Mar 10 2008 3:50 pm
Subject: Access network share from ASP.NET
Hi all,

I need to access a file on a network share from an ASP.NET application
(using methods like file.readalltext). Of course ASP.NET doesn't have access
to that share. But I do have both UserID and password of a user who does
have access. How do I use them to supply credentials for  file.readalltext
method (similar how I can do that for WebClient with NetworkCredentials)?

Thanks!

Yuriy.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
sloan  
View profile  
 More options Mar 10 2008, 4:03 pm
Newsgroups: microsoft.public.dotnet.framework.aspnet
From: "sloan" <sl...@ipass.net>
Date: Mon, 10 Mar 2008 16:03:20 -0400
Local: Mon, Mar 10 2008 4:03 pm
Subject: Re: Access network share from ASP.NET

Quickest way is impersonation with asp.net.

Inside of

<system.web>

  <authentication mode="Windows" />
  <identity impersonate="true" userName="mycompany\myname" password="mypwd"
/>

 </system.web>

That should give you something to search on.

"Yuriy Galanter" <y...@galanter.net> wrote in message

news:eq0HNgugIHA.2004@TK2MSFTNGP05.phx.gbl...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
George Ter-Saakov  
View profile  
 More options Mar 10 2008, 4:51 pm
Newsgroups: microsoft.public.dotnet.framework.aspnet
From: "George Ter-Saakov" <gt-...@cardone.com>
Date: Mon, 10 Mar 2008 16:51:26 -0400
Local: Mon, Mar 10 2008 4:51 pm
Subject: Re: Access network share from ASP.NET
Here you go....Exactly what you want without using impersonation.

#region WIN API Declarations

//used in calling WNetAddConnection2

[StructLayout(LayoutKind.Sequential)]

public struct NETRESOURCE

{

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;

}

//WIN32API - WNetAddConnection2

[DllImport("mpr.dll",

CharSet = System.Runtime.InteropServices.CharSet.Auto)]

private static extern int WNetAddConnection2A(

[MarshalAs(UnmanagedType.LPArray)] NETRESOURCE[] lpNetResource,

[MarshalAs(UnmanagedType.LPStr)] string lpPassword,

[MarshalAs(UnmanagedType.LPStr)] string lpUserName,

int dwFlags);

[DllImport("mpr.dll",

CharSet = System.Runtime.InteropServices.CharSet.Auto)]

private static extern int WNetCancelConnection2A(

[MarshalAs(UnmanagedType.LPStr)] string lpName,

int dwFlags, int fForce);

#endregion

private byte[] GetFSMSFile(string 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 = WNetAddConnection2A(nr, _sFSMSShareUserPassword, _sFSMSShareUser,
0);

if (iErr > 0)

throw new Exception("Can not connect to FSMS share folder");

FileStream st = null;

try

{

st = new FileStream(_sFSMSShare + "\\" + 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();

WNetCancelConnection2A(_sFSMSShare, 0, -1);

}
}
"Yuriy Galanter" <y...@galanter.net> wrote in message

news:eq0HNgugIHA.2004@TK2MSFTNGP05.phx.gbl...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Yuriy Galanter  
View profile  
 More options Mar 12 2008, 8:27 am
Newsgroups: microsoft.public.dotnet.framework.aspnet
From: "Yuriy Galanter" <y...@galanter.net>
Date: Wed, 12 Mar 2008 08:27:29 -0400
Local: Wed, Mar 12 2008 8:27 am
Subject: Re: Access network share from ASP.NET
Thanks guys, you pointed me in the right direction and I got it working.
Great group!

Yuriy.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
lib...@gmail.com  
View profile  
 More options Oct 29 2012, 10:15 pm
Newsgroups: microsoft.public.dotnet.framework.aspnet
From: lib...@gmail.com
Date: Mon, 29 Oct 2012 19:15:38 -0700 (PDT)
Local: Mon, Oct 29 2012 10:15 pm
Subject: Re: Access network share from ASP.NET
Yuriy Galanter於 2008年3月12日星期三UTC+8下午8時27分29秒寫道:

> Thanks guys, you pointed me in the right direction and I got it working.
> Great group!

> Yuriy.

I have the same problem, but I did not get it work. Would u mind give me a complete example?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »