Download File

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2007
Posts: 53
Reputation: dotNetDummi is an unknown quantity at this point 
Solved Threads: 0
dotNetDummi's Avatar
dotNetDummi dotNetDummi is offline Offline
Junior Poster in Training

Download File

 
0
  #1
Dec 10th, 2007
Hi experts,
I need a linkbutton/button to download the files which my clients have uploaded.

Below is my upload method and it works.

  1. protected void uploadFile()
  2. {
  3. String projectID = (String)Session["projId"];
  4. //change the file name
  5. if (!FileUpload.FileName.Equals(""))
  6. {
  7. // Create a new folder in Docs folder (folder name = projectID)
  8. System.IO.Directory.CreateDirectory(Server.MapPath("Docs/") + projectID);
  9.  
  10. // Save the file into the new folder.
  11. FileUpload.PostedFile.SaveAs(Server.MapPath("Docs/" + projectID + "/" + FileUpload.FileName));
  12. lblFile.Text = FileUpload.FileName + " is uploaded!";
  13. lblFile.Visible = true;
  14.  
  15. }
  16. }//end of method


However, it's not working for downloading of file (in another asp)
May I know how can I do that?

  1. protected void btnLink_OnClientClick(object sender, EventArgs e)
  2. {
  3. String projectID = (String)Session["projId"];
  4. String file1 = System.IO.Path.GetFileName(Server.MapPath("Docs/" + pid + "/"));
  5. }

The files format that are uploaded are not consistent. Usually it's excel, word or pdf format.

Please help. Thanks!
Serene Joey
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 18
Reputation: shaulf is an unknown quantity at this point 
Solved Threads: 4
shaulf's Avatar
shaulf shaulf is offline Offline
Newbie Poster

Re: Download File

 
0
  #2
Dec 10th, 2007
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...
Shaul
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 53
Reputation: dotNetDummi is an unknown quantity at this point 
Solved Threads: 0
dotNetDummi's Avatar
dotNetDummi dotNetDummi is offline Offline
Junior Poster in Training

Re: Download File

 
0
  #3
Dec 10th, 2007
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
Serene Joey
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 437
Reputation: Fungus1487 is on a distinguished road 
Solved Threads: 50
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Pro in Training

Re: Download File

 
0
  #4
Dec 10th, 2007
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\
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 53
Reputation: dotNetDummi is an unknown quantity at this point 
Solved Threads: 0
dotNetDummi's Avatar
dotNetDummi dotNetDummi is offline Offline
Junior Poster in Training

Re: Download File

 
0
  #5
Dec 10th, 2007
Thanks for your reply.

Nope, I realised that variable ''file'' is empty.
But I thought that's the way to get the filename and extension in a directory path?

May I know how to do that?
Last edited by dotNetDummi; Dec 10th, 2007 at 8:24 pm.
Serene Joey
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 437
Reputation: Fungus1487 is on a distinguished road 
Solved Threads: 50
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Pro in Training

Re: Download File

 
0
  #6
Dec 10th, 2007
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
  1. FileInfo finfo = new FileInfo(Server.MapPath(MyFile));
  2. 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
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 437
Reputation: Fungus1487 is on a distinguished road 
Solved Threads: 50
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Pro in Training

Re: Download File

 
0
  #7
Dec 10th, 2007
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
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 53
Reputation: dotNetDummi is an unknown quantity at this point 
Solved Threads: 0
dotNetDummi's Avatar
dotNetDummi dotNetDummi is offline Offline
Junior Poster in Training

Re: Download File

 
0
  #8
Dec 10th, 2007
Thanks for your reply.
You're fast.

Actually the thing is I wouldn't know what are the files that are being uploaded in the first place.
Serene Joey
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 53
Reputation: dotNetDummi is an unknown quantity at this point 
Solved Threads: 0
dotNetDummi's Avatar
dotNetDummi dotNetDummi is offline Offline
Junior Poster in Training

Re: Download File

 
0
  #9
Dec 10th, 2007
okay, I pass a filename already. It works.

Now I have to solve the problem.
To download the files which is "unknown" to my clients' users.
Serene Joey
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 53
Reputation: dotNetDummi is an unknown quantity at this point 
Solved Threads: 0
dotNetDummi's Avatar
dotNetDummi dotNetDummi is offline Offline
Junior Poster in Training

Re: Download File

 
0
  #10
Dec 10th, 2007
I got it . I used another method found online.

  1. DirectoryInfo diSource = new DirectoryInfo(Server.MapPath("Docs/" + pid + "/EP/"));
  2. string ExactFilename = string.Empty;
  3.  
  4. foreach (FileInfo file in diSource.GetFiles(@"*.*"))
  5. {
  6. ExactFilename = file.FullName;
  7. }
  8. System.Diagnostics.Process.Start(ExactFilename);

Just that it opened the application immediately without the filedialog box.
Serene Joey
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC