Re: Webrequest and shared files
From: John K. (tsubs04_at_hotmail.com)
Date: 05/19/04
- Next message: Luis E Valencia: "Store password not in plain text"
- Previous message: Mei Qin: "How to pass variable to AppendHeader"
- In reply to: William F. Robertson, Jr.: "Re: Webrequest and shared files"
- Next in thread: William F. Robertson, Jr.: "Re: Webrequest and shared files"
- Reply: William F. Robertson, Jr.: "Re: Webrequest and shared files"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 19 May 2004 09:56:05 -0700
Thanks Bill,
I guess I will have to do something as what your're giving example of.
(Still slightly curious about if it's possible to do it via the Webrequest class though - it would save me some small amount of code to rewrite.).
Cheers,
John
----- William F. Robertson, Jr. wrote: -----
If you can access the file through UNC I would recommend doing it that way.
This link has lots of examples:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemIOFileStreamClassTopic.asp
Here is some sample code to read the file into a byte array.
FileStream fileStream = new FileStream( @"\\server\share\file.xls",
FileMode.Open, FileAccess.Read, FileShare.Read);
BinaryReader reader = new BinaryReader( fileStream );
byte [] bytes = reader.ReadBytes( ( int ) fileStream.Length );
bytes now holds all the content of the file.
bill
"John K" <tsubs04@hotmail.com> wrote in message
news:B8146A9D-8D9D-4A23-A733-0B1E87FF7952@microsoft.com...
> Well, the current state of this application is using the setup that you
assumed
> (a virtual directory pointing to the unc share), but I was thinking that
maybe it would
> be better to access the file directly rather than via the UNC share (hence
my wondering
> if what the preferred best practise when choosing between these 2
options). If going directly
> I would eliminate a potential fail-over point (e.g. the webserver going
down, or being restarted etc...)
>> From the Framework class library reference:
>> "WebRequest descendants are typically registered to handle a specific
protocol, such as HTTP or FTP, but can be registered to handle a request to
a specific server or path on a server."
>> So there should be some way connect to a share \\server\share - but I
haven't found the right syntax for it as yet.
> I can access the files by entering my unc share in the browser so I know
the unc file path is correct.
>> John
>> ----- William F. Robertson, Jr. wrote: -----
>> I also was assuming you had a virtual directory set up called "share"
that
> points to \\server\share and has all the associated permissions.
>> Also, the URI you are using in your Create method, try placing that
straight
> into a browser and make sure you can open that way.
>> Can you not just access the file through UNC?
>> //You will also need to set the GetReponse to the WebResponse object.
> WebResponse response = request.GetResponse();
>> //this probably isn't the only way to do this.
> System.IO.Stream stream = response.GetResponseStream();
> StreamReader reader = new StreamReader( stream );
>> string s = reader.ReadToEnd();
>> response.Close()
>> HTH,
>> bill
>> "John K" <tsubs04@hotmail.com> wrote in message
> news:E6E874F4-7004-4738-A765-E0B399127AE1@microsoft.com...
>> Thanks Bill,
>>> However, I think I'm missing the crucial bit here...
>>> So are you saying that for a UNC share (e.g.
"\\server\share\file.xml" )
> the code would be the following:
>>> WebRequest request = WebRequest.Create(
> "http://server/share/file.xml" );
>> request.PreAuthenticate = true;
>> request.Credentials = new NetworkCredential( "user", "pass" );
>>> request.GetResponse();
>>> I believe the syntax of the URI has to be different for the UNC
share,
> surely? I've tried a couple of different variants
>> but usually get a logon denied related error, or that it can't find
the
> network resource.
>>> Regards,
>> John
>>>> ----- William F. Robertson, Jr. wrote: -----
>>> WebRequest request = WebRequest.Create(
"http://server/file1.xls" );
>> request.PreAuthenticate = true;
>> request.Credentials = new NetworkCredential( "user", "pass" );
>>> request.GetResponse();
>>> Now, this will work for integrated NT authentication. If you
are
> using
>> forms authentication this won't help you.
>>> I personally use UNC paths for getting files that way you can
use the
> NTFS
>> security, plus I think it is a more efficient use of bandwidth
> transferring
>> files this way, as opposed to http.
>>> HTH,
>>> bill
>>> "John K." <tsubs04@hotmail.com> wrote in message
>> news:BD7D8952-A640-4FEB-A3D1-691C4EC4BA6A@microsoft.com...
>>> Hi,
>>>> I was wondering if it's possible to use the WebRequest class to
> access a
>> file on windows shared folder with authentication? If yes,
what would
> the
>> syntax be? I've tried to look this up in the references
available but
> to no
>> avail.
>>>> Also, is it safer (better practise) in an LAN environment to use
> HTTP
>> requests to access shared files (via ASP.NET) rather than UNC
file
> shares?
>>>> TIA,
>>> Regards,
>>> John
>>>>
- Next message: Luis E Valencia: "Store password not in plain text"
- Previous message: Mei Qin: "How to pass variable to AppendHeader"
- In reply to: William F. Robertson, Jr.: "Re: Webrequest and shared files"
- Next in thread: William F. Robertson, Jr.: "Re: Webrequest and shared files"
- Reply: William F. Robertson, Jr.: "Re: Webrequest and shared files"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|