Hi. I'm building an ASP.NET site which is hosted on a remote server. When I
try to create a new file using StreamWriter I must specify the drive location
where the file will be saved. I don't have file access anywhere on the
remote server, and therefore I can't figure out how I can create a file. Is
it possible to utilize StreamWriter to create a new file and somehow display
it for the user to save, without actually saving the file programatically?
Or is there anyway I can work around this issue?
Thanks all. 7 2942
What sort of file is that?
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET] http://msmvps.com/blogs/egoldin http://usableasp.net
"Mike" <Mi**@discussions.microsoft.comwrote in message
news:62**********************************@microsof t.com...
Hi. I'm building an ASP.NET site which is hosted on a remote server.
When I
try to create a new file using StreamWriter I must specify the drive
location
where the file will be saved. I don't have file access anywhere on the
remote server, and therefore I can't figure out how I can create a file.
Is
it possible to utilize StreamWriter to create a new file and somehow
display
it for the user to save, without actually saving the file programatically?
Or is there anyway I can work around this issue?
Thanks all.
Howdy,
Yes, there is. Use combination of Response.BinaryWrite(),
Response.AddHeader(). I posted similar example here: (skip file related code,
and replace Response.WriteFile with Response.BinaryWrite(yourStream)) http://msdn.microsoft.com/newsgroups...c-ef9943cb38e8
In case of any issues, let us know.
--
Milosz
"Mike" wrote:
Hi. I'm building an ASP.NET site which is hosted on a remote server. When I
try to create a new file using StreamWriter I must specify the drive location
where the file will be saved. I don't have file access anywhere on the
remote server, and therefore I can't figure out how I can create a file. Is
it possible to utilize StreamWriter to create a new file and somehow display
it for the user to save, without actually saving the file programatically?
Or is there anyway I can work around this issue?
Thanks all.
Hi,
Milosz Skalecki [MCAD] wrote:
Howdy,
Yes, there is. Use combination of Response.BinaryWrite(),
Response.AddHeader(). I posted similar example here: (skip file related code,
and replace Response.WriteFile with Response.BinaryWrite(yourStream)) http://msdn.microsoft.com/newsgroups...c-ef9943cb38e8
In case of any issues, let us know.
If it's a StreamWriter, it's probably text. I find that to write text
back directly to the Response this kind of code works well:
StreamReader input = null;
StreamWriter output = null;
try
{
// Clear the response to avoid any unwanted
// additions to the file.
Response.Clear();
output
= new StreamWriter( Response.OutputStream );
Response.ContentType = "text/ascii";
output.WriteLine( "Hello world" );
}
catch ( Exception )
{
// There was an error --clear the response
// and return a HTML formatted error message.
Response.Clear();
Response.ClearHeaders();
Response.ContentType = "text/html";
Response.Write( "We're sorry, there was an error." );
}
finally
{
if ( output != null )
{
// Flush the output stream to avoid losing
// something on the line...
output.Flush();
output.Close();
}
// Flush the response and close it.
Response.Flush();
Response.Close();
Response.End();
}
HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Hi Laurent,
I hope you are well. I believe he wanted to display 'save as dialog' box
automatically, instead of displaying content that user can copy from window,
that's why i went for Content-Disposition : fileattachement
Respect :)
--
Milosz
"Laurent Bugnion [MVP]" wrote:
Hi,
Milosz Skalecki [MCAD] wrote:
Howdy,
Yes, there is. Use combination of Response.BinaryWrite(),
Response.AddHeader(). I posted similar example here: (skip file related code,
and replace Response.WriteFile with Response.BinaryWrite(yourStream)) http://msdn.microsoft.com/newsgroups...c-ef9943cb38e8
In case of any issues, let us know.
If it's a StreamWriter, it's probably text. I find that to write text
back directly to the Response this kind of code works well:
StreamReader input = null;
StreamWriter output = null;
try
{
// Clear the response to avoid any unwanted
// additions to the file.
Response.Clear();
output
= new StreamWriter( Response.OutputStream );
Response.ContentType = "text/ascii";
output.WriteLine( "Hello world" );
}
catch ( Exception )
{
// There was an error --clear the response
// and return a HTML formatted error message.
Response.Clear();
Response.ClearHeaders();
Response.ContentType = "text/html";
Response.Write( "We're sorry, there was an error." );
}
finally
{
if ( output != null )
{
// Flush the output stream to avoid losing
// something on the line...
output.Flush();
output.Close();
}
// Flush the response and close it.
Response.Flush();
Response.Close();
Response.End();
}
HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Hi again,
Actually good call he could just add to your example:
Response.AddHeader("Content-Disposition", "attachment;
filename=\"test.txt\"");
Regards
--
Milosz
"Milosz Skalecki [MCAD]" wrote:
Hi Laurent,
I hope you are well. I believe he wanted to display 'save as dialog' box
automatically, instead of displaying content that user can copy from window,
that's why i went for Content-Disposition : fileattachement
Respect :)
--
Milosz
"Laurent Bugnion [MVP]" wrote:
Hi,
Milosz Skalecki [MCAD] wrote:
Howdy,
>
Yes, there is. Use combination of Response.BinaryWrite(),
Response.AddHeader(). I posted similar example here: (skip file related code,
and replace Response.WriteFile with Response.BinaryWrite(yourStream)) http://msdn.microsoft.com/newsgroups...c-ef9943cb38e8
>
In case of any issues, let us know.
If it's a StreamWriter, it's probably text. I find that to write text
back directly to the Response this kind of code works well:
StreamReader input = null;
StreamWriter output = null;
try
{
// Clear the response to avoid any unwanted
// additions to the file.
Response.Clear();
output
= new StreamWriter( Response.OutputStream );
Response.ContentType = "text/ascii";
output.WriteLine( "Hello world" );
}
catch ( Exception )
{
// There was an error --clear the response
// and return a HTML formatted error message.
Response.Clear();
Response.ClearHeaders();
Response.ContentType = "text/html";
Response.Write( "We're sorry, there was an error." );
}
finally
{
if ( output != null )
{
// Flush the output stream to avoid losing
// something on the line...
output.Flush();
output.Close();
}
// Flush the response and close it.
Response.Flush();
Response.Close();
Response.End();
}
HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Excellent responses...Thank you both for your great suggestions!
"Milosz Skalecki [MCAD]" wrote:
Hi again,
Actually good call he could just add to your example:
Response.AddHeader("Content-Disposition", "attachment;
filename=\"test.txt\"");
Regards
--
Milosz
"Milosz Skalecki [MCAD]" wrote:
Hi Laurent,
I hope you are well. I believe he wanted to display 'save as dialog' box
automatically, instead of displaying content that user can copy from window,
that's why i went for Content-Disposition : fileattachement
Respect :)
--
Milosz
"Laurent Bugnion [MVP]" wrote:
Hi,
>
Milosz Skalecki [MCAD] wrote:
Howdy,
Yes, there is. Use combination of Response.BinaryWrite(),
Response.AddHeader(). I posted similar example here: (skip file related code,
and replace Response.WriteFile with Response.BinaryWrite(yourStream)) http://msdn.microsoft.com/newsgroups...c-ef9943cb38e8
In case of any issues, let us know.
>
If it's a StreamWriter, it's probably text. I find that to write text
back directly to the Response this kind of code works well:
>
StreamReader input = null;
StreamWriter output = null;
try
{
// Clear the response to avoid any unwanted
// additions to the file.
Response.Clear();
output
= new StreamWriter( Response.OutputStream );
>
Response.ContentType = "text/ascii";
>
output.WriteLine( "Hello world" );
}
catch ( Exception )
{
// There was an error --clear the response
// and return a HTML formatted error message.
Response.Clear();
Response.ClearHeaders();
Response.ContentType = "text/html";
Response.Write( "We're sorry, there was an error." );
}
finally
{
if ( output != null )
{
// Flush the output stream to avoid losing
// something on the line...
output.Flush();
output.Close();
}
// Flush the response and close it.
Response.Flush();
Response.Close();
Response.End();
}
>
HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
>
Hi,
Milosz Skalecki [MCAD] wrote:
Hi again,
Actually good call he could just add to your example:
Response.AddHeader("Content-Disposition", "attachment;
filename=\"test.txt\"");
Regards
Yes. I had that in my initial draft of the reply first, then I removed
it because it was not clear to me if he wanted the file displayed in the
same window, or with a "Open/Save" dialog.
Greetings,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: John Howard |
last post by:
I have the following in a jythonc program to be executed in a html
file.
f1 = open("filename","r")
I get message about filePermission read error. Program compiles and
jar file is created....
|
by: Jakob Bieling |
last post by:
Hi,
I was wondering why there are file access modes, which you have to
specify when opening the file. I am specifically talking about the 'read',
'read-write' and 'write' distinction. As far as...
|
by: Cable |
last post by:
Hello,
I am hoping that someone can answer a question or two regarding file
access. I have created an app that reads an image from a file then
displays it (using OpenGL). It works well using...
|
by: Jason Hurder |
last post by:
Hello folks,
I am experiencing a rather strange problem. I have written a service
that attempts to open a file on a network share via a FileStream object.
When I try to open the file from my...
|
by: Zach |
last post by:
The formatting system of my HD is NTFS.
When I right click on a file in Windows Explorer, I get a
Properties Window with only two tabs: "General" and
"Summary". I don't get a Security Tab,...
|
by: OpticTygre |
last post by:
Hi folks,
I have a function:
Public Function CreateDelta(ByVal FileName1 As String, ByVal FileName2 As
String) As String
If Not File.Exists(FileName2) Then
File.Create(FileName2)
End If
|
by: Duffman |
last post by:
Hi,
I have what seems to be a common problem, but the solutions I've found don't
seem to work. I would like to use a web service to create a file at a UNC
location in a shared file. Currently...
|
by: Amie |
last post by:
Hi,
My .NET application has a script that checks whether an image file on a
remote server exists using File.Exists.
>From my localhost (Server A), I can access the image file via network
path...
|
by: Matt MacDonald |
last post by:
Hi all,
If this isn't the write forum for this question, I appologize, but
it's kind of a mix of ASP.NET and IIS. Anyway, my question is this.
If an ASP.NET site is writing to a file, does the...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |