Click here to Skip to main content
13,085,936 members (88,249 online)
Rate this:
Please Sign up or sign in to vote.
See more:

iam developing a website using,c#(web location:file system ).
can any one help me...

i want to download the file that is displayed in the list box after the search.
i have done the searching of file from the server.

and the code i used is as follows:

string s = "",s1=""; //to get the file name
// string files = "";
string filename = '*' + fileNameTextBox.Text + '*';
DirectoryInfo MyDir;
ArrayList CellarList = new ArrayList();
MyDir = new DirectoryInfo(Server.MapPath("files/"));
string path = (Server.MapPath("files/"));
//FileInfo[] MyFiles = MyDir.GetFiles("*.*");
string[] fileList = System.IO.Directory.GetFiles(path, filename);
foreach (string file in fileList)
  s = file.ToString();
  s1 = s.Replace(path, "");

so plz help....
thanks in advance
Posted 16-Dec-11 17:50pm
Ragi Gopi1.3K
Updated 16-Dec-11 18:08pm
Orcun Iyigun 17-Dec-11 0:08am
Added tags.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

1. You Can Simpally Use; command in javascript. it will directly open a file if browser support other wise shows download dialog box.

or you can use a proper download button i.e

        string sFilename;
        sFilename = Server.MapPath("todown.doc");
        byte[] btFile = System.IO.File.ReadAllBytes(sFilename);
        Response.AddHeader("Content-Disposition", "attachment;filename=" + sFilename + "");
        Response.OutputStream.Write(btFile, 0, btFile.Length);
Ragi Gopi 17-Dec-11 0:42am

what should i do to display in a panel in web page itself....

thank u for your help...
plz help me for this query tooo...
Technoses 22-Dec-11 7:56am
you can use iframe and set src=filepath. it runs if browser supports that feature..
Ragi Gopi 22-Dec-11 23:20pm
can u plz show me an example.....plz help me
Technoses 23-Dec-11 11:25am
<iframe src="pdffilename.pdf" style="width:400px; height:400px" />
Ragi Gopi 3-Jan-12 5:19am
protected void bl_procedures_Click(object sender, BulletedListEventArgs e)

string path = Server.MapPath("PROCEDURES/" + bl_procedures.Items[e.Index].Text);
System.IO.FileInfo file = new System.IO.FileInfo(path);
Label2.Text = file.Name +"###" + file.FullName;
//Response.AddHeader("Content-Disposition", "inline; filename=" + file.Name);

//Response.AddHeader("content-length", file.Length.ToString());
//Response.ContentType = ReturnExtension(file.Length.ToString());

frmWord.Attributes["src"] = file.Name;
catch(Exception ex)
Label2.Text = ex.ToString();


done this code but not displaying data in iframe ..its showing error...what to do???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 17 Dec 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100