C# - Store Files In ASP Website Then Download To Browser

Sep 1, 2010

I'm creating an Excel file in C# on my asp.net web site. Then, I want to save this file somewhere within the web server's files, and send that file to the browser for the user to download. I've got it working on my local system in the dev environment, but I'm not getting the file addressing right. How can I store a file in "~ParentFolderSubFolderfile.ext". Then send that file to the browser for user download.

String outputFile = Utilities.writeToExcelFile("", MapPath(@"~ReportFilesTempFilesDropShipData.xls"), table);
DownloadFile(outputFile);
public void DownloadFile(string fname)
{
string path = fname;
string name = Path.GetFileName(path);
string ext = Path.GetExtension(path);
string type = "";
// set known types based on file extension
if (ext != null)
{
switch (ext.ToLower())
{
case ".htm":
case ".html":
case ".aspx":
case ".asp":
type = "text/HTML";
break;
case ".xls":
case ".xlsx":
case ".csv":
type = "Application/x-msexcel";
break;
case ".pdf":
type = "Application/pdf";
break;
case ".txt":
type = "text/plain";
break;
case ".doc":
case ".docx":
case ".rtf":
type = "Application/msword";
break;
}
}
Response.AppendHeader("content-disposition",
"attachment; filename=" + name);
if (type != "")
Response.ContentType = type;
Response.WriteFile(path);
Response.End();
}

Again, this works fine on my local pc, but when I move it to the server I get an error for accessing the path. And the path listed in the error code is NOT where I want the file to go.

View 2 Replies


Similar Messages:

Web Forms :: Download PDF And Doc Files In Browser

Mar 16, 2010

I am developing a application similar to a forum. I want to attach documents in .doc and .PDF formats. I want to know how could i download these attachments and open directly in a browser without saving the downloaded document.

View 2 Replies

Web Forms :: When Select The File For Download, A Small Browser Appears To Ask Where You Which To Store This Data To?

Jan 17, 2011

I am using Visual Studio 2008 Express and I wish to select a file for downloading. I have seen websites that when you select the file for download, a small browser appears to ask you where you which to store this data to.How do I get that component ?? I know the path on the web design where my data is store, and if its must be a hyperlink, I can make a hyperlink to that path.All I wasnt is when the user select the file he wish to download, a small browser appears to ask where he was that store to.Can someone tell me what I need to do to get that ?

View 7 Replies

Web Forms :: Download Multiple Files And Store Them In Client Machine Folder Or Directory

Jul 16, 2013

Download multiple file from server and stored in client browse directory.

View 1 Replies

White Labeling Website / So Consumer Can Use Download Store With Their Brand Name?

Jan 12, 2010

I am working in one of the company which sells music online. we want to white label our website so the different consumer can use our download store with their brand name.

View 1 Replies

Download Files From Secure Website Programmatically (c#)?

Dec 3, 2010

I've to download files from our 38 clients secure websites. They are our data resources. Currently data collection process is manual. Logon to the site, login with username and password, then download files, save to local folder, close window once download is completed. We are trying to automate download process. Plan is to handle login part with code and directly show list of filename to User with check box , so User can select files and click to save.

Rest all will be handled programtically. Once download is complete the status for that file will change to "Saved" or "Download Complete. I'm working on Window 7, VS2008(C# asp.net). Trying to make it work with WebClient class. It'll be great if you can post some source code or guide me to link or post for solution.

View 2 Replies

HttpHandlers / Modules :: Files Won't Download From Website When The Site Has A Custom HTTP Handler Mapped

Nov 28, 2010

When I have a HttpHandler class in C#/ASP.NET mapped to a file extension in IIS any file with that extension fails to download/display in web browsers (it's downloaded as a 0-byte file in some browsers and nothing at all in other browsers). After removing the application mapping for the HttpHandler in IIS so it doesn't call the IHttpHandler class in C#, the web browser downloads the file successfully.

This was tested with an IHttpHandler class in C# that has an empty ProcessRequest method.

View 2 Replies

How To Store Files (pdf And Word Files) Into Sql Database

Jan 30, 2010

how to store files (pdf and word files) into sql database and how to display that files with an option of "save" , "open" window from sql data base when user click. i am doing project using c# + asp.net web application

View 1 Replies

Creating Mobile Website Page To Download Symbian .sis File To Mobile Unable To Download Properly

Dec 10, 2010

i m creating asp.net Mobile website page to download symbian .sis file to mobile ,but its not geting download properly.its working perfectly on desktop.

View 2 Replies

Configuration :: Can Store Website Contents In A Folder That Is Located On Website

Apr 27, 2010

I need to have a copy of all my pages, bin fold, data folder, etc stored in a folder in the root of project called installation.

Once I have copied the contents of my web site into the installation folder how can I tell the complie/run process to ignore that folder ?

View 1 Replies

How To Download Image From Browser

Jan 27, 2011

Is there any way i can download image using asp.net

I want to dialog box opened to save it

View 1 Replies

Unable To Get Server Side Event To Store Data In Sql For Download History.

Nov 8, 2010

I want to create log user file download history.I have shown all of my in gridview and in template filed use hyperlink to download file.But I didn't get server side event to store data in sql for download history.I try to manage it using JavaScript but when pop blocker
catch file download then database entry two times ,

View 2 Replies

.net - Browser Store The Cache Item?

Jan 24, 2011

If i enable client side cache in my asp.net application where it store that cache controls in my computer

View 1 Replies

Opening A Force Download In A New Browser Window?

May 17, 2010

I have a button event when forces a download to the users browser, but I would like to know whether there is a way for the download open in a new sized browser window. Is there away to do this?

View 5 Replies

JsonResult Shows Up A File Download In Browser?

Apr 3, 2010

I'm trying to use jquery.Ajax to post data to an ASP.NET MVC2 action method that returns a JsonResult. Everything works great except when the response gets back to the browser it is treated as a file download instead of being passed into the success handler. Here's my code:

Javascript:

[Code]....


If I open the downloaded file the json is exactly what I'm looking for and the mime type is shown as application/json. What am I missing to make the jquery.ajax call receive the json returned?

View 3 Replies

Mobiles :: Prompt To Download Instead Of Display In Web Browser?

Oct 17, 2010

I using vs2008 web application to develop my wap site. I got an URL like below:

www.askquestion.com/contentlocation/motorsound.images

But when i browse the URL above in phone browse, the phone will show the image file in phone browse. But what i need to do is prompt user to download and save it.

View 3 Replies

How To Store Value In Session If In Browser Cookie Is Disabled

Dec 1, 2010

Can i still store value in session if in browser cookie is disabled?

View 2 Replies

C# - How To Download And Display Excel Spread Sheet Within The Browser

Feb 14, 2010

Need to navigate to Excel spread sheet and display in the browser.

how could I do that ?

View 5 Replies

How To Open / Save Dialog In Browser When Download A Pdf File In C#

Aug 4, 2010

I have a mail list where i can select many mails and download (with/without opening the mail). During the download process i update the mail status(download/open) and show the content in pdf. In normal browser dialog opens where user can save open or cancel options exits. But if the user cancel then the update process done on the mail should not happen. so i think about doing the update process if the user clicks open or save but how can i identity that client control (i think it depend on the browser)

The issue is present if i download and unopened mail and click cancel button in the dialog box the pdf creation code i have done is in this link

[URL]

which i used to open that dialog in browser to save pdf

View 2 Replies

C# - Detect If A File Is Being Downloaded By A Browser Or A Download Manager?

Dec 12, 2010

I am curious as to how the file sharing sites like rapidshare detect users downloading files through download managers.

How do you enable an ASP.NET web application to prevent downloads from a download manager.

View 5 Replies

Cannot Download Files From An FTP Server

Jun 22, 2010

downloading files from an FTP server. The FTP server produces new files from time to time. so my application needs to Download only the "NEW" files and disregard what i have already downloaded previously. I have a time stamp on when was the last download time. I Using FtpWebRequest, WebRequestMethods.Ftp.ListDirectory, WebRequestMethods.Ftp.GetDateTimestamp. The problem is the ListDirectory gives me all the List in the FTP directory and i have to loop all the way down starting again from the start to the last file and check it with my last time stamp to DL the NEW files another problem is the FTP Directory contains 30,000 Files so it would take long until ill find the my last download time to start again on that point..

View 16 Replies

How To Download Files With Different Extensions

Feb 9, 2010

I have a web based application, asp.net with vb.net. However, i have different files with different extension such as .CSV and .RTF, and the clients need to download these files in regularly bases

View 18 Replies

How To Download Files From Server

Feb 23, 2010

I want to enable the users of my website to download the files from the server, but I can do it only with those files which are inside the website's folder(by creating hyperlinks to those files).

How to enable the users to download files from server which are not in the website's folder but somewhere else on the server.

View 3 Replies

How To Start And Download Dll Files

Mar 1, 2010

bump on this WebForms MVP and i was able to download the DLL files but i don't know how to start. how to integrate it in VS, etc..

View 5 Replies

How To Force Client Browser To Download Images From Server Rather Using Its Cache

May 20, 2010

Assume a simple aspx data entry page in which admin user can upload an image as well as some other data. They are stored in database and the next time admin visits that page to edit record, image data fetched and a preview generated and saved to disk (using GDI+) and the preview is shown in an image control.

This procedure works fine for the first time however if the image changes (a new one uploaded) the next time the page is surfed it shows previously uploaded image. I debugged the application and everything works correct. The new image data is in database and new preview is stored in Temp location however the page shows previous one. If I refresh the page it shows the new image preview. I should mention that preview is always saved to disk with one name (id of each record as the name).

I think that is because of IE and other browsers use client cache instead of loading images each time a page is surfed. I wonder if there is a way to force the client browser to refresh itself so the newly uploaded image is shown without user intervention.

View 2 Replies







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