| | |
Download File
Thread Solved |
Hi experts,
I need a linkbutton/button to download the files which my clients have uploaded.
Below is my upload method and it works.
However, it's not working for downloading of file (in another asp)
May I know how can I do that?
The files format that are uploaded are not consistent. Usually it's excel, word or pdf format.
Please help. Thanks!
I need a linkbutton/button to download the files which my clients have uploaded.
Below is my upload method and it works.
ASP.NET Syntax (Toggle Plain Text)
protected void uploadFile() { String projectID = (String)Session["projId"]; //change the file name if (!FileUpload.FileName.Equals("")) { // Create a new folder in Docs folder (folder name = projectID) System.IO.Directory.CreateDirectory(Server.MapPath("Docs/") + projectID); // Save the file into the new folder. FileUpload.PostedFile.SaveAs(Server.MapPath("Docs/" + projectID + "/" + FileUpload.FileName)); lblFile.Text = FileUpload.FileName + " is uploaded!"; lblFile.Visible = true; } }//end of method
However, it's not working for downloading of file (in another asp)
May I know how can I do that?
ASP.NET Syntax (Toggle Plain Text)
protected void btnLink_OnClientClick(object sender, EventArgs e) { String projectID = (String)Session["projId"]; String file1 = System.IO.Path.GetFileName(Server.MapPath("Docs/" + pid + "/")); }
The files format that are uploaded are not consistent. Usually it's excel, word or pdf format.
Please help. Thanks!
Serene Joey
Not 100% sure what you are trying to do? Upload or Download a file. For download you need to replace the response stream with the file. This link is pretty good for downloading:
http://www.xefteri.com/articles/show.cfm?id=8
Use lots of try catch blocks...
http://www.xefteri.com/articles/show.cfm?id=8
Use lots of try catch blocks...
Shaul
Hi. Thanks for your reply.
I'm trying to download files. By the way, I'm using C# so doesn't really quite understand the VB code.
I tried this .
protected void btnLink_OnClientClick(object sender, EventArgs e)
{
String pid = Convert.ToString(Session["pid"]);
String file = System.IO.Path.GetFileName(Server.MapPath("Docs/" + pid + "/EP/"));
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + file);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file);
Response.End();
}
But it doesn't work .
Error msg : Access to the path 'C:\Documents and Settings\[machineName]\My Documents\[projectName]' is denied.
Is it because I upload at my documents?
What should I do? Please help. Thanks
I'm trying to download files. By the way, I'm using C# so doesn't really quite understand the VB code.
I tried this .
protected void btnLink_OnClientClick(object sender, EventArgs e)
{
String pid = Convert.ToString(Session["pid"]);
String file = System.IO.Path.GetFileName(Server.MapPath("Docs/" + pid + "/EP/"));
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + file);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file);
Response.End();
}
But it doesn't work .
Error msg : Access to the path 'C:\Documents and Settings\[machineName]\My Documents\[projectName]' is denied.
Is it because I upload at my documents?
What should I do? Please help. Thanks
Serene Joey
set your permissions to allow access to my documents.
saying that i remember not being allowed access to a servers My Documents folder even with permissions set.
use another file location i.e.
c:\WEB APP FILES\
saying that i remember not being allowed access to a servers My Documents folder even with permissions set.
use another file location i.e.
c:\WEB APP FILES\
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
well theres no file your just referencing the directory "Docs/##/EP/" ? try passing a filename through ?
also 'file.Length.ToString());' will not return the files size as its just a string variable you will need to do a
then use the 'FileInBytes' attribute to show the file length
also 'file.Length.ToString());' will not return the files size as its just a string variable you will need to do a
ASP.NET Syntax (Toggle Plain Text)
FileInfo finfo = new FileInfo(Server.MapPath(MyFile)); long FileInBytes = finfo.Length;
then use the 'FileInBytes' attribute to show the file length
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
after re-reading you say you want them to download THE files.
the only way to do a batch download is either open a window for each file, create a zip file on the fly with all files inside, or have aprompt for them to download file sone at a time by selecting them
the only way to do a batch download is either open a window for each file, create a zip file on the fly with all files inside, or have aprompt for them to download file sone at a time by selecting them
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
I got it . I used another method found online.
Just that it opened the application immediately without the filedialog box.
ASP.NET Syntax (Toggle Plain Text)
DirectoryInfo diSource = new DirectoryInfo(Server.MapPath("Docs/" + pid + "/EP/")); string ExactFilename = string.Empty; foreach (FileInfo file in diSource.GetFiles(@"*.*")) { ExactFilename = file.FullName; } System.Diagnostics.Process.Start(ExactFilename);
Just that it opened the application immediately without the filedialog box.
Serene Joey
![]() |
Similar Threads
- download any file!!! (Windows NT / 2000 / XP)
- download file on portals jsr 168 (JSP)
- download file in website (Pascal and Delphi)
- php download a file without redirecting (PHP)
- can't shut down some download file (OS X)
- can't download on ie (Web Browsers)
Other Threads in the ASP.NET Forum
- Previous Thread: Dropdown list in ASP.NET - How to get value selected
- Next Thread: copy a project to another computer
Views: 5800 | Replies: 13
| Thread Tools | Search this Thread |
Tag cloud for ASP.NET
.net 2.0 3.5 2005 ajax ajax-doc application asp asp.net asp.net-mvc asp.net_hw_sw authentication authorization beginner browser button c# captcha chat checkbox click compatible connectionstring control crystalreport dataaccesslayer database datagridview datalist delete deployment development dgv dropdown dynamically edit editor encryption expose external feedback fill flash folder form forms gridview homeedition identity iframe iis impersonation index javascript list login maps masterpage membership mysql order panelmasterpagebuttoncontrols parent problem profile purchase ratings read redirect refer request.form search security server session sessionvariables sharepoint silverlight sql sql-server sqlexpress-attach subdomain theft tracking translate-web-pages update user validation vb.net virtualdirectory vista visual-studio visualstudio vs2008 web webdevelopemnt webservice website windows-auth xml





