Solved

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

Posted on 2009-04-02
2
593 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now