Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
hai
 
iam developing a website using asp.net,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:
 
resultsList.Items.Clear();
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, "");
  resultsList.Items.Add(s1);
}
 
so plz help....
thanks in advance
Posted 16-Dec-11 18:50pm
Ragi Gopi1.3K
Edited 16-Dec-11 19:08pm
v2
Comments
Orcun Iyigun at 17-Dec-11 0:08am
   
Added tags.

1 solution

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

Solution 1

1. You Can Simpally Use window.open(fileurl); 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.Clear();
        Response.AddHeader("Content-Disposition", "attachment;filename=" + sFilename + "");
        Response.OutputStream.Write(btFile, 0, btFile.Length);
        Response.End();
  Permalink  
v2
Comments
Ragi Gopi at 17-Dec-11 0:42am
   
thanku....
 
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 at 22-Dec-11 7:56am
   
you can use iframe and set src=filepath. it runs if browser supports that feature..
Ragi Gopi at 22-Dec-11 23:20pm
   
can u plz show me an example.....plz help me
Technoses at 23-Dec-11 11:25am
   
<div>
<iframe src="pdffilename.pdf" style="width:400px; height:400px" />
</div>
Ragi Gopi at 3-Jan-12 5:19am
   
protected void bl_procedures_Click(object sender, BulletedListEventArgs e)
{

try
{
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.Clear();
//Response.AddHeader("Content-Disposition", "inline; filename=" + file.Name);

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

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
0 Afzaal Ahmad Zeeshan 256
1 OriginalGriff 251
2 BillWoodruff 240
3 Maciej Los 230
4 Sergey Alexandrovich Kryukov 195
0 OriginalGriff 6,419
1 Sergey Alexandrovich Kryukov 6,008
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,070


Advertise | Privacy | Mobile
Web02 | 2.8.1411019.1 | Last Updated 17 Dec 2011
Copyright © CodeProject, 1999-2014
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