| Author: Subodh kumar Prajapati 06 Jun 2007 | Member Level: Gold | Rating: Points: 2 |
Hi Devi, You can use the Html control or Asp control to browse the file from spacific directory. add a input button from the toolbox of Html control. and set the type is "File" of that control. now you'll see that a browser button will be displayed. now you can select the files through this browser button. To save the file, you can use this code: bttBrowse.SaveAs("c:/tt.txt");
where bttBrowse is the name of control which is added.
I think this will be help to you. If want to more information then you can tell or ask to me.
ok byeee... From : subodh kumar 9891428085
|
| Author: Arunagiri Gunasekaran 13 Oct 2008 | Member Level: Gold | Rating: Points: 5 |
Dear Devi, If you want to fetch all the files from the specific directory, then you cannot use the file upload control. You have to give the folder path manually,
After that you can use the System.IO namespace and get all the files in the given directory and move to the server.
other wise, View this link given below. I hope, it will help you to move further.
http://aspalliance.com/150_how_to_upload_files_in_asp_net
All the Best :)
|
| Author: Viji 11 Nov 2008 | Member Level: Silver | Rating: Points: 0 |
Use Follow Code:
The Controls are Treeview,Gridview
using System; using System.IO; using System.Data; using System.Data.SqlClient; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { }
private void FillDirectory(TreeNode parent, string strPath) { DirectoryInfo dr = new DirectoryInfo(strPath); if (dr.Exists) { foreach (DirectoryInfo d in dr.GetDirectories()) { TreeNode node = new TreeNode(); node.Text = d.Name; node.Value = d.FullName; node.PopulateOnDemand = true; node.SelectAction = TreeNodeSelectAction.SelectExpand; parent.ChildNodes.Add(node); } } }
protected void DirTreeview_TreeNodePopulate(object sender, TreeNodeEventArgs e) { string selectedstring = e.Node.Value; string strFileName = Path.Combine(currentFolderPath, selectedstring); FillDirectory(e.Node, strFileName); //BindDirContents(e.Node, gridviewFiles); }
public String currentFolderPath { get { if (ViewState["m_currentFolderPath"] != null) return ViewState["m_currentFolderPath"].ToString().Trim(); else return string.Empty; } set { ViewState["m_currentFolderPath"] = value; } }
private static void BindDirContents(TreeNode node, System.Web.UI.WebControls.GridView gridview) { // bind the gridview to the datasource gridview.DataSource = new System.IO.DirectoryInfo(node.Value).GetFiles(); gridview.DataBind(); }
protected void gridviewFiles_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { System.IO.FileSystemInfo item = (System.IO.FileSystemInfo)e.Row.DataItem; ImageButton imageButton = (ImageButton)e.Row.FindControl("btnItemIcon"); System.IO.FileInfo fileInfo = (System.IO.FileInfo)item;
Label lblSize = (Label)e.Row.FindControl("lblSize"); lblSize.Text = string.Format("{0:N0} KB", fileInfo.Length / 1000);
if ((fileInfo.Name.EndsWith(".rtf") || fileInfo.Name.EndsWith(".doc") || fileInfo.Name.EndsWith(".txt"))) { imageButton.ImageUrl = @"Image/doc.jpg"; } else { imageButton.ImageUrl = @"Image/voice.png"; } } }
protected void DirTreeview_SelectedNodeChanged(object sender, EventArgs e) { BindDirContents(this.DirTreeview.SelectedNode, this.gridviewFiles); }
protected void gridviewFiles_RowCommand(object sender, GridViewCommandEventArgs e) { // handle either opening the item or rebinding the grid if (e.CommandName == "ItemClick") { string name = (string)e.CommandArgument; System.IO.DirectoryInfo dinfo = new System.IO.DirectoryInfo(this.DirTreeview.SelectedNode.Value);
if (System.IO.File.Exists(System.IO.Path.Combine(dinfo.FullName, name))) { System.IO.FileInfo fileInfo = new System.IO.FileInfo(System.IO.Path.Combine(dinfo.FullName, name)); // they clicked on a file, download it to there PC this.Response.Clear(); this.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name); this.Response.WriteFile(fileInfo.FullName); this.Response.End(); } else { foreach (TreeNode node in this.DirTreeview.SelectedNode.ChildNodes) { if (node.Text == name) { node.Selected = true; node.Expanded = true; // expand the parents TreeNode parentNode = node.Parent; while (parentNode != null) { parentNode.Expanded = true; parentNode = parentNode.Parent; }
// bind the gridview to the datasource BindDirContents(node, this.gridviewFiles); break; } } } } } }
Default.aspx.txt |