Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8803089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:15:01+00:00 2026-06-14T01:15:01+00:00

I’m new at web app in ASP.NET and I came across this problem. I

  • 0

I’m new at web app in ASP.NET and I came across this problem.

I have a page whe there is a Button to download a template.xls that is previously stored at a SharePoint page. I have the download method and it’s working just fine. The template in question is being saved where it should be, on a folder where my web app is located, on my local IIS.
The problem is to open this file to the end user. I need a popup to be displayed to the user, so he can open/save this template.xls
I’m using the following :

//path on my local IIS where the file is located after the download
string _strFolderApp = "~/Arq/";
string _strFullFolderApp = _strFolderApp + _strFileName;
string apPath = System.Web.Hosting.HostingEnvironment.MapPath(_strFullFolderApp);

FileStream _FileStream = new FileStream(apPath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
// Writes a block of bytes to this stream using data from a byte array.
_FileStream.Write(_contentFile, 0, _contentFile.Length);

//opens the file
Response.Clear();
Response.AddHeader("content-disposition", "attachment; filename=" + _strFileName);
Response.ContentType = "";
Response.TransmitFile(apPath);
Response.Flush();
File.Delete(apPath);
Response.End();
# endregion

// close file stream
_FileStream.Close();

I searched online and all answers end up in using FileShare.ReadWrite so both process would work properly. But it’s not working for me, because when the code reaches Response.TransmitFile(apPath); I get an exception and popup doesn’t show.
Exception :

The process cannot access the file ‘c:\inetpub\wwwroot\MyWebApp\File\TemplateSharePoint.xlsx’ because it is being used by another process.

Please any help would be appreciated 🙂

EDIT
Code update

if (_flgSPSDownload)
        {
            System.IO.FileStream _FileStream = new System.IO.FileStream(apPath,System.IO.FileMode.Create, System.IO.FileAccess.Write);
            _FileStream.Write(_contentFile, 0, _contentFile.Length);
            _FileStream.Close();


            Response.Clear();
            Response.AddHeader("content-disposition", "attachment; filename=" + _strFileName);
            //Set the appropriate ContentType.
            Response.ContentType = "Application/x-msexcel";
            Response.TransmitFile(apPath);
            Response.Flush();
            //Write the file directly to the HTTP content output stream.
            Response.WriteFile(apPath);
            //File.Delete(apPath);

            //Process.Start(_strDestinationPath + "//" + _strFileName);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T01:15:02+00:00Added an answer on June 14, 2026 at 1:15 am

    From what I can tell, you’re opening the file-stream, and then trying to open it again, before you close it.

    Initial opening of the file:

    FileStream _FileStream = new FileStream(apPath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
    

    and

    Response.TransmitFile(apPath); 
    

    seems to be trying to open the file again.

    I would suggest calling

    _FileStream.Close();
    

    before calling TransmitFile.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have been unable to fix a problem with Java Unicode and encoding. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.