Solved

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

Posted on 2009-04-02
2
590 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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video discusses moving either the default database or any database to a new volume.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

17 Experts available now in Live!

Get 1:1 Help Now