Loading a Remote file

A

Anbu

Hi,

I want to load contents of a remote HTML file and to display it on the ASP
..NET Web Page. The remote HTML file is not under any virtual folder and the
content & location may vary for each operations.

How can I do the same?

Thanks,
Anbu
 
G

Grant Merwitz

You can use your code to Access files on the server or in shares that do not
exist in your virtual directories, regarding your ASPNET system account has
sufficient privalges, or the account IIS is using.
This can also be overcome using impersonation.

To load this file, you can include the file in a place holder on the page,
or write the file out using System.IO

Regards

Grant
 
A

Anbu

Can I have some example?

You can use your code to Access files on the server or in shares that do not
exist in your virtual directories, regarding your ASPNET system account has
sufficient privalges, or the account IIS is using.
This can also be overcome using impersonation.

To load this file, you can include the file in a place holder on the page,
or write the file out using System.IO

Regards

Grant
 
G

Grant Merwitz

Ok, here goes

I set the security on c:\test to allow everyone full control.
This is not neccesary, just your ASPNET accounts needs these privileges, or
you can impersonate a user on the server with sufficient privileges


CODE:

using System.IO;

// Specify file, instructions, and privelegdes

FileStream file = new FileStream("c:\\test\\test.txt",
FileMode.OpenOrCreate, FileAccess.Write);


// Create a new stream to write to the file

StreamWriter sw = new StreamWriter(file);

// Write a string to the file

sw.Write("Hello file system world!");

// Close StreamWriter

sw.Close();

// Close file

file.Close();



// *** Read from file ***

// Specify file, instructions, and privelegdes

file = new FileStream("c:\\test\\test.txt", FileMode.OpenOrCreate,
FileAccess.Read);

// Create a new stream to read from a file

StreamReader sr = new StreamReader(file);

// Read contents of file into a string

string s = sr.ReadToEnd();

Response.Write(s);

// Close StreamReader

sr.Close();

// Close file

file.Close();
 
A

Anbu

Thanks Grant,

I have no problem in reading the text file, but displaying at the
appropriate place. I read the document using filestream classes.

If I use Response.Write to display the HTML Contents, it prints the contents
on the TOP or BOTTOM of the ASPX page. Whereas, I want to display the
content at a particular place. Because I have many controls placed as header
and footer. Somehow, I solved the problem by using Label and LiteralControl.
Still the content does not look fine. I'm looking for an alternate...

Thanks for your help.


Ok, here goes

I set the security on c:\test to allow everyone full control.
This is not neccesary, just your ASPNET accounts needs these privileges, or
you can impersonate a user on the server with sufficient privileges


CODE:

using System.IO;

// Specify file, instructions, and privelegdes

FileStream file = new FileStream("c:\\test\\test.txt",
FileMode.OpenOrCreate, FileAccess.Write);


// Create a new stream to write to the file

StreamWriter sw = new StreamWriter(file);

// Write a string to the file

sw.Write("Hello file system world!");

// Close StreamWriter

sw.Close();

// Close file

file.Close();



// *** Read from file ***

// Specify file, instructions, and privelegdes

file = new FileStream("c:\\test\\test.txt", FileMode.OpenOrCreate,
FileAccess.Read);

// Create a new stream to read from a file

StreamReader sr = new StreamReader(file);

// Read contents of file into a string

string s = sr.ReadToEnd();

Response.Write(s);

// Close StreamReader

sr.Close();

// Close file

file.Close();
 
A

Anbu

Thanks Grant,

I have no problem in reading the text file, but displaying at the
appropriate place. I read the document using filestream classes.

If I use Response.Write to display the HTML Contents, it prints the contents
on the TOP or BOTTOM of the ASPX page. Whereas, I want to display the
content at a particular place. Because I have many controls placed as header
and footer. Somehow, I solved the problem by using Label and LiteralControl.
Still the content does not look fine. I'm looking for an alternate...

Thanks for your help.


Ok, here goes

I set the security on c:\test to allow everyone full control.
This is not neccesary, just your ASPNET accounts needs these privileges, or
you can impersonate a user on the server with sufficient privileges


CODE:

using System.IO;

// Specify file, instructions, and privelegdes

FileStream file = new FileStream("c:\\test\\test.txt",
FileMode.OpenOrCreate, FileAccess.Write);


// Create a new stream to write to the file

StreamWriter sw = new StreamWriter(file);

// Write a string to the file

sw.Write("Hello file system world!");

// Close StreamWriter

sw.Close();

// Close file

file.Close();



// *** Read from file ***

// Specify file, instructions, and privelegdes

file = new FileStream("c:\\test\\test.txt", FileMode.OpenOrCreate,
FileAccess.Read);

// Create a new stream to read from a file

StreamReader sr = new StreamReader(file);

// Read contents of file into a string

string s = sr.ReadToEnd();

Response.Write(s);

// Close StreamReader

sr.Close();

// Close file

file.Close();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top