•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 423,853 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,824 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 2550 | Replies: 13 | 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.
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 methodHowever, it's not working for downloading of file (in another asp)
May I know how can I do that?
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
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.
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
![]() |
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
.net .net framework 3.0 access adsl adsl1 adsl2 adsl2+ ajax asp cable code combo connection custom data developer development dom download dropdownlist feed internet kb kbps mbit microsoft module msdn net network news office reader reuse second skin software sql testing theme throughput upload vista weather web windows windows workflow xml xoap 240000
- download any file!!! (Windows x64 Edition)
- 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


Linear Mode