C# - Download File From Server And Then Delete

Feb 1, 2010

i am downloading a file from a server and i plan to delete the file that i have downloaded on the server after it gets downloaded on the client side. My download code is working fine but i dont know when to put the command to delete the file.

string filepath = restoredFilename.ToString();
// Create New instance of FileInfo class to get the properties of the file being downloaded
FileInfo myfile = new FileInfo(filepath);
// Checking if file exists
if (myfile.Exists)
{
// Clear the content of the response
Response.ClearContent();
// Add the file name and attachment, which will force the open/cancel/save dialog box to show, to the header
Response.AddHeader("Content-Disposition", "attachment; filename=" + myfile.Name);
//Response.AddHeader("Content-Disposition", "inline; filename=" + myfile.Name);
// Add the file size into the response header
Response.AddHeader("Content-Length", myfile.Length.ToString());
// Set the ContentType
Response.ContentType = ReturnExtension(myfile.Extension.ToLower());
//// Write the file into the response (TransmitFile is for ASP.NET 2.0. In ASP.NET 1.1 you have to use WriteFile instead)
Response.TransmitFile(myfile.FullName);
// End the response
Response.End();
}

Now i know the response.End() will stop every thing and return the value, so is there another way too do so. I need to call a function

DeleteRestoredFileForGUI(restoredFilename);

to delete the file but dont know where to put it.. i tried putting before and after Response.End() but it does not work.

View 4 Replies


Similar Messages:

Web Forms :: Delete After Prompt Download Of File?

Jul 22, 2010

I believe this question has been asked before but I still couldn't find the appropriate answer.

My scenario is like this:

When the user click on a button, it will dynamically generate a .xls and prompt the user to download.I have used transmitfile but it doesn't allows the file to be deleted. I have also used outputstream.write but it doesn't delete the file after flush. Instead it will hold onto the .xls and no modification can be done to the file.

View 4 Replies

Show Download Dialog Box In Case Of File Download - Located On Amazon Server

Jan 4, 2010

i am using amazon s3 service. now i want to show download dialog box in my asp.net application when user come on download page. i am using amazon sdk.

View 1 Replies

Web Forms :: After Client Download Then Server Delete FileExcel?

May 19, 2010

I've problem when I Export my data to Excel and response to Client.

I want :

When Client Downloaded File Excel, On server will delete that file. Current, when Export, on my Server will genaral an Excel File and I call Response.Redirect(fileExcel), Client enable Download that file.

But, If I don't delete that file on server then my server will full by time.Whether any way to download from FileStream Or something the same?

Or any body have an other way to after Client Download then Server delete fileExcel?

View 2 Replies

Web Forms :: Can't Start File Download From Server Side Using .aspx File In IE7

Mar 26, 2011

This below code i have used in my aspx page for file download.

Response.AppendHeader("content-disposition", "attachment; filename="" + emailAttachment.FileName + "";");
Response.ContentType = "application/octet-stream";
Response.OutputStream.Write(emailAttachment.Data, 0, emailAttachment.Data.Length);
Response.End();

This block of code display Download file Dialog for Open or Save the attached file.It's working fine in Mozila Firefox and IE8 but doesn't display Download file Dialog box in IE 7

View 2 Replies

Web Forms :: Force File Download On Remote File Server

Sep 13, 2010

I'm trying to force a large (200+ MB) file to download that's on a remote server. The problem is that I can't use the "WriteFile()" function, since I'm not using a virtual path. Then, when I try:

Response.AppendHeader("content-disposition",

View 17 Replies

SQL Server :: Delete Image File From File System

Oct 9, 2010

I have a web site that you can upload images, the image path is saved in the ImgPath field in the data database and retrieves the image and displays it in the grid view. I want to be able to delete the image from a folder within my project when I delete the record. I'm trying to delete it from the Detailsview_ItemDeleting event.

View 4 Replies

C# - Download File From Server .net?

Jan 5, 2010

I want to download a file from server to a local host.i have a code from the net which should work but is not working

protected void Button4_Click(object sender, EventArgs e)
{
//To Get the physical Path of the file(test.txt)[code]....

now when the button is clicked the file should be downloaded from the server to the local host computer... but nothing seems to be happening...i have the test.txt on the desktop of the serer... the save file option also does not come on the client side..I publish the files and put it in the inetpub folder of the server and run the GUI from the client side.. everything works except this...this program downloads a file if it is present in the inetpub folder.. instead i want to download from any location within the server...

View 3 Replies

Download XML File To The IIS Server Not To The Client?

Oct 5, 2010

I'm trying to do the following in ASP.NET (with c#):

1. On page Load, download an XML file from a different website to the IIS server, in a subdirectory of the application directory called "downloadedFiles"

I know that WebClient.DownloadFile() can download a file, but this only seems to download the file to the client's machine. I am interested in downloading it to the actual IIS server (so that it can be utilized throughout the lifetime of more than one session). Does anyone know how this could be performed?

Specifically, I'm trying to download an XML file from a website (as an example: [URL]) . How could I download that XML file onto my actual IIS server?

View 2 Replies

Web Forms :: Download File From FTP Server?

Dec 14, 2010

if any one know how to download the file from the FTP server using credential of the ftp. code step by step in C#.net.

View 2 Replies

Download File To Server - Code Some Vb?

Mar 24, 2010

Is there a way I can code some vb whereby the server would download a file from a given URL from an external website elsewhere? For example, if I entered the url for the 7-Zip exe, it would then download that from SourceForge of wherever, and save it to the server.

View 3 Replies

Download File From Server To Client's Pc

Jul 19, 2010

How do i download a file from server to the client pc using asp.net, im using c# with vs 2005. I have tried with WebCient but it is downloading on the server itself. I want to download a particular file to the client PC.

View 4 Replies

Upload File To Server And Download Them Later

Mar 11, 2011

here code which you have used and is working to upload file using file upload control and them download with open/saveas/cancel dialog.

View 3 Replies

MVC :: Download Audio File From Server

Nov 1, 2010

string url = string.Empty;
string title = string.Empty;
//full file path should be assigned to url
//file name with format should be assigned to title

url = "p[URL]abc.mp3";
title = "abc.mp3.mp3";
WebClient wc = new WebClient();
byte[] byteData;
Response.ContentType="application/octet-stream";
Response.AddHeader("content-disposition","attachment;filename="+title);
Response.BinaryWrite(byteData= wc.DownloadData(@url));

View 3 Replies

Web Forms :: Download File From SQL Server?

Aug 24, 2010

I am having an issue downloading files that I have store in SQL Server. I have no problem in a WinForm. What am I doing wrong in my code?

[Code]....

I have a window open from another page because I was having an issue doing this while the page was ajaxified. The FileData part of the code is a structure that holds a memorystream and 2 strings and they are returning proper values. The window opens up and then closes almost immediately when the page loads.

View 2 Replies

C# - Download A File From Remote Server?

Mar 17, 2010

The below code works fine for downloading a file from a current pc.plz suggest me how to download it from remote server using ip address or any method

protected void Button1_Click(object sender, EventArgs e)
{
const string fName = @"C:ITFSPDFbillsFebruaryAA.pdf";
FileInfo fi = new FileInfo(fName);
long sz = fi.Length;
Response.ClearContent();
Response.ContentType = MimeType(Path.GetExtension(fName));
Response.AddHeader("Content-Disposition", string.Format("attachment; filename = {0}", System.IO.Path.GetFileName(fName)));
Response.AddHeader("Content-Length", sz.ToString("F0"));
Response.TransmitFile(fName);
Response.End();
}
public static string MimeType(string Extension)
{
string mime = "application/octetstream";
if (string.IsNullOrEmpty(Extension))
return mime;
string ext = Extension.ToLower();
Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext);
if (rk != null && rk.GetValue("Content Type") != null)
mime = rk.GetValue("Content Type").ToString();
return mime;
}

View 2 Replies

Download A File From A External Server Through .net & C#?

Feb 24, 2011

First,I uploaded a file in a external server and got a url from that server.Now i want to download that uploaded file from the external server through that url which i got from that server through asp.net and c#.I wrote a c# code to download that file, but during that process i got an exception "Exception of type 'System.OutOfMemoryException' was thrown".The following is the c# code which i wrote to download:

double dlsize=0;
string Url = "http://www.sample.com/download.zip"; \File Size: 75MB
int lastindex = Url.LastIndexOf("/");
string TempUrlName = Url.Substring(lastindex + 1, Url.Length - (lastindex + 1));[code]....

View 1 Replies

Download An Xml File Generated On The Server?

Jan 27, 2010

In my app I want to download an xml file generated on the server when I press the button. I have a code

[Code]....

But it doesn't work. I want a Save As dialog to see, but now I only see the xml structure in the Firebug in the response.

View 4 Replies

Web Forms :: Download A File From Ftp Server?

Feb 24, 2010

I am using VS2005 with FrameWork 2.0 . I am trying to download a file from ftp server with the following code:

[Code]....

the server i am downloading from is a UNIX server and dosen't use Passive mode. when executing the function i got the following error:

The remote server returned an error: (550) File unavailable (e.g., file not found, no access).and because it's a common error message i used :

[Code]....

and got the following error message:

550 No access to SYS$LOGIN:. Requested action not taken

View 1 Replies

Web Forms :: Download More Than One File From Server

Jul 18, 2013

I need to download more than one file from server and download into loacl. Using gzipStream class in system.io.compression.

View 1 Replies

SQL Server :: Unable To Delete Mdf And Log File From Server Cuteftp

Oct 16, 2010

I am using VS 2008 with SQL in express edition . I have made my website and hosted it on server with cuteftp .Now i want to change

the website so when i tried to delete all files the App_data folder does not delete .

So i am unable delete my mdf and log file which are in this folder. It says file error.

I always use SQL in design window in VS and know less of coding in SQL.

View 5 Replies

Web Forms :: Excel File Download From Server?

Mar 7, 2010

I am creating Excel file from code. This code is working fine in my local server. because it is local iis and local VS. When I deployed in the server. I am not able to see (download) excel to client browser. How can we give access to see excel in client browser?

[Code]....

View 3 Replies

Web Forms :: Download Doc File From Server With 3.5 Framework And IIS 6.0?

Apr 6, 2010

I am trying to download doc file from server and it show download same aspx file instead of document file.my code is working with .net framework 2.0 and IIS 6.0 but its not working with .net 3.5 framework and IIS6.0

===========================================

[Code]....

View 2 Replies

Web Forms :: Download .xlsx File From Server

Sep 16, 2010

Iv created a web application using vb.net 2005. Its working fine and running fine on the server (Microsoft Server 2003). The problem i have is to dowload a file from the same server using vb.net. I tried using this code but it gives me a : "is not a virtual path" error.

Response.ContentType =
"file/xlsx"
Response.AppendHeader(
Response.TransmitFile(
Response.End()
"Content-Disposition",
"attachment; filename=AllReports.xlsx")".xlsx")

View 5 Replies

Web Forms :: HttpWebRequest - Download File From Web Server?

Oct 19, 2010

I am working on a .NET1.1 application. I want to download file on the web servers using httpwebresponse.

How to download a file on the webserver using httpwebresponse using C# code?

View 3 Replies







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