Solved

Receiving "Could not open file, sharing violation" error when streaming data file from ASP.NET website

Posted on 2009-04-02
2
596 Views
Last Modified: 2012-05-06
Hi,

I am attempting to stream data from a database, to a file.  Everything is working good, until you click "Open" on the browsers "Do you wish to open or save this file" dialog box.  When you click open, the browser appears to download the file, then the associated application tries to open the file, then I get the error attached.

I am not sure how to code this so that the file opens without a sharing violation.

This only happens in Internet Explorer (Version 7)
The file opens successfully in Firefox and Google Chrome.
var buffer = (byte[])dsData.Tables[0].Rows[0][0];
        Response.ContentType = "application/EDI.Document";
        Response.AddHeader("content-disposition", "attachment; filename=file.edi");
        Response.AddHeader("Content-Length", buffer.Length.ToString());
        Response.BinaryWrite(buffer);

Open in new window

error.JPG
0
Comment
Question by:kevinjd
2 Comments
 
LVL 12

Accepted Solution

by:
williamcampbell earned 500 total points
ID: 24054339
How big is the file? Over 4MB there may be a problem
Try a Response.End after the write and maybe a Response.Flush

Curios why it's trying to write file[2] .. is there one there already? Did a download succees? Are there two downloads occuring at the same time?

Few things to think about.


0
 

Author Comment

by:kevinjd
ID: 24054388
The file is under 1k.  786 bytes.

Every time I run this code to test, it downloads the file.  So each time, it appends a number on the temp file name, which is fine.

It seems IE is keeping the file locked for whatever reason.  As stated, this does not happen in Firefox/Chrome.  They both allow the file to be opened instantly.

The same thing happened after adding         Response.End();
        Response.Flush();


0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question