User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Nov 2007
Posts: 52
Reputation: dotNetDummi is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
dotNetDummi's Avatar
dotNetDummi dotNetDummi is offline Offline
Junior Poster in Training

Download File

  #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.

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?

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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: California
Posts: 18
Reputation: shaulf is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 4
shaulf's Avatar
shaulf shaulf is offline Offline
Newbie Poster

Re: Download File

  #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  
Join Date: Nov 2007
Posts: 52
Reputation: dotNetDummi is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
dotNetDummi's Avatar
dotNetDummi dotNetDummi is offline Offline
Junior Poster in Training

Re: Download File

  #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  
Join Date: Apr 2007
Location: Birmingham
Posts: 378
Reputation: Fungus1487 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 37
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Whiz

Re: Download File

  #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  
Join Date: Nov 2007
Posts: 52
Reputation: dotNetDummi is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
dotNetDummi's Avatar
dotNetDummi dotNetDummi is offline Offline
Junior Poster in Training

Re: Download File

  #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 7:24 pm.
Serene Joey
Reply With Quote  
Join Date: Apr 2007
Location: Birmingham
Posts: 378
Reputation: Fungus1487 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 37
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Whiz

Re: Download File

  #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
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
Reply With Quote  
Join Date: Apr 2007
Location: Birmingham
Posts: 378
Reputation: Fungus1487 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 37
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Whiz

Re: Download File

  #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  
Join Date: Nov 2007
Posts: 52
Reputation: dotNetDummi is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
dotNetDummi's Avatar
dotNetDummi dotNetDummi is offline Offline
Junior Poster in Training

Re: Download File

  #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  
Join Date: Nov 2007
Posts: 52
Reputation: dotNetDummi is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
dotNetDummi's Avatar
dotNetDummi dotNetDummi is offline Offline
Junior Poster in Training

Re: Download File

  #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  
Join Date: Nov 2007
Posts: 52
Reputation: dotNetDummi is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
dotNetDummi's Avatar
dotNetDummi dotNetDummi is offline Offline
Junior Poster in Training

Re: Download File

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

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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 3:53 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC