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 2958
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**@discussio ns.microsoft.co mwrote in message
news:62******** *************** ***********@mic rosoft.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.Binary Write(),
Response.AddHea der(). I posted similar example here: (skip file related code,
and replace Response.WriteF ile with Response.Binary Write(yourStrea m)) 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.Binary Write(),
Response.AddHea der(). I posted similar example here: (skip file related code,
and replace Response.WriteF ile with Response.Binary Write(yourStrea m)) 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.Output Stream );
Response.Conten tType = "text/ascii";
output.WriteLin e( "Hello world" );
}
catch ( Exception )
{
// There was an error --clear the response
// and return a HTML formatted error message.
Response.Clear( );
Response.ClearH eaders();
Response.Conten tType = "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.Binary Write(),
Response.AddHea der(). I posted similar example here: (skip file related code,
and replace Response.WriteF ile with Response.Binary Write(yourStrea m)) 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.Output Stream );
Response.Conten tType = "text/ascii";
output.WriteLin e( "Hello world" );
}
catch ( Exception )
{
// There was an error --clear the response
// and return a HTML formatted error message.
Response.Clear( );
Response.ClearH eaders();
Response.Conten tType = "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.AddHea der("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.Binary Write(),
Response.AddHea der(). I posted similar example here: (skip file related code,
and replace Response.WriteF ile with Response.Binary Write(yourStrea m)) 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.Output Stream );
Response.Conten tType = "text/ascii";
output.WriteLin e( "Hello world" );
}
catch ( Exception )
{
// There was an error --clear the response
// and return a HTML formatted error message.
Response.Clear( );
Response.ClearH eaders();
Response.Conten tType = "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...Tha nk you both for your great suggestions!
"Milosz Skalecki [MCAD]" wrote:
Hi again,
Actually good call he could just add to your example:
Response.AddHea der("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.Binary Write(),
Response.AddHea der(). I posted similar example here: (skip file related code,
and replace Response.WriteF ile with Response.Binary Write(yourStrea m)) 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.Output Stream );
>
Response.Conten tType = "text/ascii";
>
output.WriteLin e( "Hello world" );
}
catch ( Exception )
{
// There was an error --clear the response
// and return a HTML formatted error message.
Response.Clear( );
Response.ClearH eaders();
Response.Conten tType = "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.AddHea der("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. Just the html code gives message.
Any ideas?
|
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 I can tell, it only makes
sure, you (the programmer) do not accidently write to it when you opened it
for reading. To me, this seems like another one of those things that just
make life harder.
I am asking this, because I am writing a wrapper...
|
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 fopen() with fgetc()
to access each byte. I have decided to move further with this app and
allow the user to select the first file of an image sequence and it
will play the sequence back at at 24 frames per second. I have almost
everything...
|
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 service, I get the "Access is
denied" error. However, if I try to open the file from a GUI
application, I can open the file without problem. I've tried using the
FileIOPermissions object to get around the error with no luck. Obviously
I am missing...
|
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, allowing me to
set access permission. Given that the formatting system
is NTFS, why am I not seeing the required tab, and why
am I not seeing the appropriate Properties form?
Please assist.
| |
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 I'm just running it locally and saving
the file locally using my machines UNC path.
I have given user ASPNET full control over the folder I want to write the
file to. I've also tried using the web config identity impersonation to use
my user...
|
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 (\\servername\foldername\image.jpg) or virtual directory
(../foldername/image.jpg) within my application.
When I moved the app to a test server (Server B), it still works fine.
|
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 file get written as
soon as the request is processed or once the IIS Worker Process queues
it up? For example:
Users 1, 2, and 3 all hit the page that called the file write at the
same time. Am I left to deal with a file access violation...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |