Web Forms :: File Download Using Response.BinaryWrite() - Odd Behavior

Jan 8, 2010

I am using a gridview to display (open or save) files that have been uploaded into a SQL 2005 server. I have a templatefield within the gridview that contains a linkbutton that does a postback to GetUploadedFile.aspx that then fires the response.binarywrite() code. The code seems to work fine and opens/saves the files correctly. But once this has completed and I try and click on another button on the page, instead of doing the appropriate action it re-fires the getuploadedfile.aspx binarywrite code and opens up the "Open/Save/Cancel" dialog again.

[Code]....

[Code]....

[Code]....

View 4 Replies


Similar Messages:

Response.BinaryWrite - Incorrect Name Of File Opened On A Client Side

Jan 24, 2011

[Code]....

The dilaogbox that offers me to save the file shows incorrect chars if documentFileName has name not in ASCII format. What I'm supposed to do to have the file name displayed correctly in this dialogbox and to have this file opened under the same name in MS Word, Excel whatever else?

View 5 Replies

Web Forms :: Add Redirect Button After Response.BinaryWrite

Feb 3, 2011

I need add a buttom to my aspx page.

My code is

byte[] buffer;
FileStream fs = new FileStream(@"C:info.pdf", FileMode.Open);
try
{

[Code]....

I need a click button after the code. How can I do this.

View 5 Replies

Web Forms :: BinaryWrite Image From Database Is Corrupt On Download?

Feb 18, 2011

We have been downloading Office 2003 documents stored in our database as images successfully using our ASP.NET 2.0 web portals. We recently started storing Office 2007 documents and though they upload without issue, the download and render does not work. The file opens with the error - "The file is corrupt and cannot be opened". It is only with Office 2007 files we see this. The web server supports the Office 2007 MIME types. We also apply the correct content-type when uploading a file to the database. Sample BinaryWrite code below. Is there something I am overlooking unique to Office 2007 files?

Dim MyData()
As
Byte
....
MyData = dreader("document")
....
Response.ContentType =
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
Response.AddHeader("Content-Length",
MyData.Length.ToString())
Response.AddHeader("Content-Disposition",
"attachment; filename=" & dreader("file_name").ToString)
Response.BinaryWrite(MyData)
Response.Flush()

View 10 Replies

Error On Response.BinaryWrite PDF?

Feb 12, 2010

I am generating a pdf file to a MemoryStream, and then using Response.BinaryWrite to display that in the browser. But if a pdf reader is not installed, then I get an ugly error message.

Is there something I can do so that if no pdf reader is installed, I can display a friendly message or provide the option to save the file to the system?

View 2 Replies

C# - Response.BinaryWrite Gives Error On Production?

Dec 6, 2010

I'm using localReport to print PDF (SQL REPORTVIEWER). It works fine on localhost. When I move the application to Production (64 bits windows 2008) it gives me an error. (see below)

I put the renderedbytes in a Session in USERCONTROL and I do window.open('Program1.aspx')...

In page load of Program1.aspx I try to retrieve the Session variable and process.... I think this statement cause the error "Response.BinaryWrite (...) etc".

It works on my local pc (Vista 32bits)...

[Code]....

Server Error in '/' Application. Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[Code]....

View 2 Replies

Response.BinaryWrite Not Working In Firefox And Chrome?

Dec 7, 2010

I have binary data - it is png picture.

I use Response.BinaryWrite to display this picture.

Unfortunately it works only in Internet Explorer. In Firefox and Chrome it shows long text of strange symbols.

What's wrong with BinaryWrite? How to solve this?

I may not say to asp:Image to show this picture, I may not indicate ImageURL, becouse there's no URL. This picture is response from webrequest. And webrequest may not be indicated in URL because I set some parameters not in QueryString but in post data.

View 2 Replies

Web Forms :: Client Download .csv File From Server Using Response.TransmitFile?

Sep 3, 2010

I am using the code below to enable clients to download a .csv file from my server.

The problem I am having is that when the file is saved to the client computer the file name is prefixed and suffixed with an underscore which leads to a file type of .csv_ which is obviously not a recognised file type.

How can I strip the underscores from the file name at the transmit stage?

Dim FileName As String = LstBox1.SelectedItem.ToString
Dim FilePath As String = "~/temp" & FileName
Response.Clear()
Response.ContentType = "text/csv"
Response.AddHeader("Content-Disposition", "attachment; filename=" & FileName & "")
Response.TransmitFile(FilePath)
Response.End()

View 9 Replies

Web Forms :: Load File From Database And Write A Response To Let User Download?

Mar 10, 2010

I am a newbie of asp.net.

The environment is .net 3.5 and C#.

There are files stored in sql server (datatype of column is varbinary in the database).

each record is in one record in that table (FILE_TABLE).

And there is another table (PATH_TABLE) to store the files paths.

for example,

when the user download the folder A (select an item on the tree and click a button on the client side),

there is one sub-folder B and two files A-1 and A-2.

in folder B, there is two files B-1 and B-2.

then, at the code behind (server), the server will get the files from the database and convert them (including the files and subfolders) to a .zip file (or other compressed files)

and then write a response (using the method HttpResponse.BinaryWrite(Byte[] xxx) )

to client side and let the user download.

after the download, the user can extract the compressed file and the structure of the folders and files keep unchanged.

View 4 Replies

Forms Data Controls :: How To Download A File Then Either Redirect Or Refresh The Page (after Response.end)

Oct 12, 2010

I am using some code similar to the code below to open a word document on my ASP.net app. Once the file has been downloaded and opened I then want to either redirect to another page or refresh the screen but nothing works after response.end and if i add it before response.end the browser never downloads the file?

[Code]....

[Code]....

View 6 Replies

Web Forms :: How To Use Httpcontext.response.transmitfile Or Other Method To Download A File From A Network Drive

Feb 25, 2010

Does anyone know how to use httpcontext.response.transmitfile or any other httpcontext function to download a file from a network drive instead of local drive?

When I tried to use context.Response.TransmitFile(DownloadPath) to download files, the DownloadPath has to be local drive. If it's a network drive, the download failed.

View 3 Replies

C# - Download .xlsx File Using Response.TransmitFile()?

Feb 16, 2010

I'm working on some code that generates an Excel spreadsheet server-side and then downloads it to the user. I'm using ExcelPackage to generate the file.

The generation is working just fine. I can open the generated files using Excel 2007 with no issues. But, I'm having trouble downloading the file with Response.TransmitFile().

Right now, I have the following code:

//Generate the file using ExcelPackage
string fileName = generateExcelFile(dataList, "MyReportData");
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.ContentType = "application/vnd.xls"
Response.Charset = "";
Response.TransmitFile(fileName);

When Excel 2007 opens the file downloaded as above, it gives the "file format doesn't match extension" warning. After clicking past the warning, Excel displays the raw xml contents of the file. If I change the file extension, like so Response.AddHeader("content-disposition", "attachment;filename=FileName.xlsx");
Excel 2007 gives an "Excel found unreadable content in the file" error, followed by a dialog that offers to locate a converter on the web. If I click "no" on this dialog, Excel is able to load the data.

I've also experimented with different MIME types, like application/vnd.ms-excel and application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, combined with file extensions of .xls and .xlsx. All combinations result in one of the two behaviors mentioned above. What is the correct combination of file extension and MIME type to use in this scenario? What else could cause this failure, other than an improper MIME type or extension? FYI, this is occurring with Visual Studio's built-in development web server. I haven't yet tried this with IIS.

View 1 Replies

Response.TransmitFile "Response.End" To Download File

Mar 31, 2010

I have following function which is called from a button click event

[Code]....

I am creating a zip file on the fly and wanted to download this file.Problem is that in Internet explorer when I click the button the download accelrator comes with file name as my page saying resume opendialogueif i click open then DAP window close and normal windows download manager comes but the event of my button fires multiple time?I don't know what to do with it

View 6 Replies

Architecture :: Write A Response To Let Users Download A Big File From DB?

Mar 11, 2010

I am a newbie of handling memory.

in my web apps, files are stored as varbinary in sql server.

my goal is to make a response to let users to download the files.

if there is a file (500 MB) stored in one record in the sql server,

what is the best way to let users download it?

I found that , in code-behind, if the files are loaded as byte[] objects, it uses the memory.

for example, the datalength of a file in the database is 500 MB.

the byte[] for this file uses 500 MB memory. am I correct?

how about the filestream? if the file is loaded as a filestream object in code-behind.s

does it also take 500 MB memory?

View 2 Replies

How To Use Httpcontext.response.transmitfile Or Other Function To Download A File From A Network?

Feb 25, 2010

Does anyone know how to use httpcontext.response.transmitfile or any other httpcontext function to download a file from a network drive instead of local drive? When I tried to use context.Response.TransmitFile(DownloadPath) to download files, the DownloadPath has to be local drive. If it's a network drive, the download failed.

View 2 Replies

C# - HttpContext.Current.Response Write File After Download Manager Starts?

Dec 17, 2010

I'm trying to create a ZIP file on the fly which might contain a few thousands of pictures.

[code]....

My question:

Is there a way to initiate the download (let the download manager on client side popup), and then start writing on the stream?

I monitored w3wp.exe (IIS) process, and it seems that the data is being written on memory instead of Stream.

When w3wp.exe memory usage riches a certain number, it releases the memory and nothing happens (no download).

View 2 Replies

C# - Generate File For Download Using Response.Write And Change Elements On The Webpage?

Aug 25, 2010

I am trying to change the text of a asp:textbox and collapse some ajaxToolkit:CollapsiblePanelExtenders within some ascx controls on my page as well as output a dynamically generated file. I have no problem collapsing the CollapsiblePanelExtenders and changing the text of the textbox from the codebehind or outputting a file. The problem arises when I want BOTH of these events to happen on the same postback. Unfortunately using Response.Write negates all of the other changes to the page.

View 1 Replies

HTTP Response Behavior - Cause Browser To Prompt

Jan 5, 2011

I have two very similar pieces of ASP.NET code that send a file in an HTTP Reponse to the client. They should cause the browser to prompt to save the file. The first one works, the second one doesn't. The HTTP responses as seen in Fiddler are below.

Working:
HTTP/1.1 200 OK
Cache-Control: private
Content-Length: 228108
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 4.0.30319
content-disposition: attachment; filename=Report.xlsx
Date: Wed, 05 Jan 2011 12:17:48 GMT
<binary data>

Not working:
HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Wed, 05 Jan 2011 12:19:21 GMT
X-AspNet-Version: 4.0.30319
Content-Length: 228080
content-disposition: attachment; filename=report 2.xlsx
Cache-Control: private
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Connection: Close
<binary data>

When the first one is seen in Fiddler the browser correctly prompts to save the file. When the second one is seen in Fiddler, nothing observable happens in the browser. Same behaviour in both chrome and firefox.

EDIT: ASP.NET code that produces the second response

Response.Buffer = false;
Response.ContentType = @"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AppendHeader("content-length", genstream.Length.ToString());
Response.AppendHeader("Content-Disposition", string.Format("attachment; filename={0}.xlsx", filename));
byte[] buffer = new byte[1024];
genstream.Position = 0;
int n;
while ((n = genstream.Read(buffer, 0, 1024) ) > 0)
{
Response.OutputStream.Write(buffer, 0, n);
}

View 4 Replies

C# - Response.Write Behavior Varies In The Given Scenario?

Jun 16, 2010

When i POST the page using the following code, the Response.write("Hey") doesn't write the content ("Hey") to the parent page

<form method="post" name="upload" enctype="multipart/form-data"
action="http://localhost:2518/Web/CrossPage.aspx" >
<input type="file" name="filename" />
<input type="submit" value="Upload Data File" name="cmdSubmit" />
</form>

But When i use following code , and POST the data, the Response.write("Hey") can be obtained in the parent page

[code]...

View 4 Replies

C# - BinaryWrite Of MHT File Not Treated As MHT By IE

Aug 13, 2010

I have an MHTML file which has embedded images. The MHTML is generated on the server and then I will typically deliver the file using a BinaryWrite. I've also tried Server.Transfer, Response.Write after converting to ASCII and writing the file to disk and using a Response.WriteFile. In any of these cases the resulting file is not (it appears) treated as an mht file. For setting the image, I've tried Content-ID and Content-Location. The image URL shows up as cid:example1 when viewed in IE8. When opening up the file after saving to disk it shows up as mhtml:file://C:Documents and Settings enjynitoDesktopoutput634172401776447258.mht!cid:example1. Or while browsing with one of the methods that work you get [URL]

The Output.MimeType is message/rfc822. I've also tried application/octet-stream and multipart/related. Writing the file to disk and using a Response.Redirect works. Accessing the file with a direct URL works. Saving the file to disk and then opening the file works. It seems IE is assuming an HTML result to the request and not deciphering the new content type. But you can do things like this for dynamic style sheets, scripts, etc... so I don't really believe that. I couldn't see any glaring differences. I just tried and the BinaryWrite works fine in Opera. If I absolutely have to worry about writing to a temporary directory and then redirecting to the file I will. I was just hoping to avoid having to clean up the temporary files. Is what I want to do not possible? An example of writing the file is below.

if (response != null && response.Output != null)
{
Response.Clear();
Response.AddHeader("Content-Type", response.Output.MimeType);
Response.AddHeader("Content-Disposition", "attachment;filename=output" + DateTime.UtcNow.Ticks.ToString(CultureInfo.InvariantCulture) + "." + response.Output.Extension);
// Response.Write( System.Text.Encoding.ASCII.GetString(response.Output.Bytes));
Response.BinaryWrite(response.Output.Bytes);
//Response.Clear();
//Server.Transfer("/ISV/Forms/Test/output634172397522707394.mht");
//Response.Clear();
//Response.WriteFile( Server.MapPath("/ISV/Forms/Test/output634172397522707394.mht"));
Response.Flush();
Response.End();

View 1 Replies

Web Forms :: Download File Using New Window When Download Button Is Clicked

Sep 2, 2013

I need to download  a .mp3 file from a folder. during download a new blank page should open and after downloading it should close automatically.

View 1 Replies

Web Forms :: How To Hide Servername And Url Download Using Response.redirect

Mar 27, 2010

HOw to hide servername and url download by using reponse.redirect in asp.net 2.0.

View 8 Replies

Web Forms :: Hide Download Path Using Response.redirect?

Feb 5, 2010

How can i Hide download path in asp.net when i am using reponse.redirect("abc.zip") ?

Example if i used reponse.redirect("abc.zip") but if reponse.redirect("abc.zip") is wrong path it will display error with our full download path .if it right path it working fine .

If Clscon.rs.Read Then
Response.Redirect(Clscon.rs(9))
End If

View 7 Replies

Web Forms :: Controlling File Name Of The File Opened Directly From File Download Dialog?

Jul 26, 2010

I am downloading file from database using the following code. This code downloads an excel file from the database which has a macro attached to it when it is opened. This macro reads file name of the excel file and uses it for its computation. Everthing works file if user saves the file on his harddisk and then open if but if he directly opens the file from the dialog(by hitting 'Open' button) then file name of the opened excel file comes out be the name of the webform that has the above code and this leads to error in the macro. Is there any option through which i can control the name of the file if user directly opens the file from dialog or the option to disable or remove 'Open' button form the dialog?

[Code]....

View 2 Replies

C# - Response.Redirect Causes Download Of The Swf?

Feb 20, 2010

I have a flash image slider with a button below each image. When i press that button, the user is redirected to a new page where i add that image product to my cart. The problem is that after doing the adding, i want to redirect the user back to the initial page.

The code:

protected void Page_Load(object sender, EventArgs e)
{
addProductToBasket(getCategoryIdFromUrl(), getProductIdFromUrl());
Response.Redirect(Request.UrlReferrer.ToString());
}

note that in Firefox is working fine but in IE or Chrome it is DOWNLOADING the swf...If i comment Response.Redict(...) the user remains on this page so the click button is working well, only the redirect seems to be the problem.

Edit: The problem seems to be that Request.UrlReferrer keeps as link not the initial page containing the swf but the swf itself.

So, instead of doing redirect to:[URL] if does redirect to the swf contained on the Index.aspx page[URL]

Solved: with a session variable where i keep the initial page's url

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved