string FileName = Path.GetFileName(flUpdUpload.PostedFile.FileName);
string Extension = Path.GetExtension(flUpdUpload.PostedFile.FileName);
string FolderPath = ConfigurationManager.AppSettings["FolderPath"];
string FilePath = Server.MapPath("~/UploadFiles/" + FileName);
whereas Uploadfiles is a folder in my solution. u can have it or leave.try this
Wael Abu Rez...
Member
53 Points
40 Posts
Re: Save File Dialog into Web Based Application
Apr 24, 2012 09:13 PM|LINK
Many thanks :) but...
How can I let the user determine the path !!!!!! in addition, where can i put my table adapter in the above code :D ?
i need an example, as simple as possible, showing the user selects a path and a type to be saved as from DataAdapter or DataTable
Br,
ManojNR
Member
114 Points
59 Posts
Re: Save File Dialog into Web Based Application
Apr 25, 2012 06:32 AM|LINK
string FileName = Path.GetFileName(flUpdUpload.PostedFile.FileName); string Extension = Path.GetExtension(flUpdUpload.PostedFile.FileName); string FolderPath = ConfigurationManager.AppSettings["FolderPath"]; string FilePath = Server.MapPath("~/UploadFiles/" + FileName); whereas Uploadfiles is a folder in my solution. u can have it or leave.try thisWael Abu Rez...
Member
53 Points
40 Posts
Re: Save File Dialog into Web Based Application
Apr 25, 2012 09:59 PM|LINK
HOW CAN THE USER SELECT THE PATH !!!!!!!!!!!!!!!, how can he have such a browse window to select the path and write the name ?????
Many thx
Mark-yu
Participant
888 Points
127 Posts
Re: Save File Dialog into Web Based Application
Apr 27, 2012 01:23 AM|LINK
Hi Wael Abu Rezeq,
Browse server side file system, blow might help you.
.aspx file
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm19.aspx.cs" Inherits="WebDev.WebForm19" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><title>test</title></head> <body> <form id="Form1" method="post" runat="server"> <asp:ListBox id="lstDirs" style="Z-INDEX: 101; LEFT: 32px; POSITION: absolute; TOP: 72px" runat="server" Width="248px" Height="208px" Font-Names="Verdana"></asp:ListBox> <asp:Button id="cmdParent" style="Z-INDEX: 109; LEFT: 176px; POSITION: absolute; TOP: 280px" runat="server" Text="Up One Level" Width="100px" Height="24px"></asp:Button> <asp:Button id="cmdShowInfo" style="Z-INDEX: 107; LEFT: 312px; POSITION: absolute; TOP: 280px" runat="server" Text="Show Info"></asp:Button> <asp:Label id="Label2" style="Z-INDEX: 104; LEFT: 312px; POSITION: absolute; TOP: 56px" runat="server" Width="192px" Height="24px" Font-Names="Verdana" Font-Bold="True" Font-Size="X-Small">Contained Files:</asp:Label> <asp:ListBox id="lstFiles" style="Z-INDEX: 102; LEFT: 312px; POSITION: absolute; TOP: 72px" runat="server" Width="280px" Height="200px" Font-Names="Verdana"></asp:ListBox> <asp:Label id="Label1" style="Z-INDEX: 103; LEFT: 32px; POSITION: absolute; TOP: 56px" runat="server" Width="216px" Height="38px" Font-Names="Verdana" Font-Bold="True" Font-Size="X-Small">Subdirectories:</asp:Label> <asp:Label id="Label3" style="Z-INDEX: 105; LEFT: 32px; POSITION: absolute; TOP: 16px" runat="server" Width="184px" Height="19px" Font-Names="Verdana" Font-Bold="True" Font-Size="Medium">Current Directory:</asp:Label> <asp:Button id="cmdBrowse" style="Z-INDEX: 106; LEFT: 32px; POSITION: absolute; TOP: 280px" runat="server" Text="Browse To Selected" Width="136px" Height="24px"></asp:Button> <asp:Label id="lblFileInfo" style="Z-INDEX: 108; LEFT: 312px; POSITION: absolute; TOP: 328px" runat="server" Width="280px" Height="80px" BorderStyle="Groove" BorderWidth="2px" Font-Names="Verdana" Font-Size="X-Small"></asp:Label> <asp:Label id="lblCurrentDir" style="Z-INDEX: 110; LEFT: 240px; POSITION: absolute; TOP: 16px" runat="server" Width="184px" Height="24px" Font-Names="Verdana" Font-Bold="True" Font-Size="Medium"></asp:Label> </form> </body> </html>.cs file
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; namespace WebDev { public partial class WebForm19 : System.Web.UI.Page { //protected System.Web.UI.WebControls.ListBox lstDirs; //protected System.Web.UI.WebControls.Button cmdParent; //protected System.Web.UI.WebControls.Button cmdShowInfo; //protected System.Web.UI.WebControls.Label Label2; //protected System.Web.UI.WebControls.ListBox lstFiles; //protected System.Web.UI.WebControls.Label Label1; //protected System.Web.UI.WebControls.Label Label3; //protected System.Web.UI.WebControls.Button cmdBrowse; //protected System.Web.UI.WebControls.Label lblFileInfo; //protected System.Web.UI.WebControls.Label lblCurrentDir; private void Page_Load(object sender, System.EventArgs e) { if (!this.IsPostBack) { string startingDir = System.Web.HttpContext.Current.Server.MapPath(@"~\");//@"c:\Temp"; lblCurrentDir.Text = startingDir; ShowFilesIn(startingDir); ShowDirectoriesIn(startingDir); } } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.cmdParent.Click += new System.EventHandler(this.cmdParent_Click); this.cmdShowInfo.Click += new System.EventHandler(this.cmdShowInfo_Click); this.cmdBrowse.Click += new System.EventHandler(this.cmdBrowse_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void ShowFilesIn(string dir) { DirectoryInfo dirInfo = new DirectoryInfo(dir); lstFiles.Items.Clear(); foreach (FileInfo fileItem in dirInfo.GetFiles()) { lstFiles.Items.Add(fileItem.Name); } } private void ShowDirectoriesIn(string dir) { DirectoryInfo dirInfo = new DirectoryInfo(dir); lstDirs.Items.Clear(); foreach (DirectoryInfo dirItem in dirInfo.GetDirectories()) { lstDirs.Items.Add(dirItem.Name); } } private void cmdShowInfo_Click(object sender, System.EventArgs e) { if (lstFiles.SelectedIndex != -1) { string fileName = Path.Combine(lblCurrentDir.Text, lstFiles.SelectedItem.Text); FileInfo selFile = new FileInfo(fileName); lblFileInfo.Text = "<b>" + selFile.Name + "</b><br>"; lblFileInfo.Text += "Size: " + selFile.Length + "<br>"; lblFileInfo.Text += "Created: "; lblFileInfo.Text += selFile.CreationTime.ToString(); lblFileInfo.Text += "<br>Last Accessed: "; lblFileInfo.Text += selFile.LastAccessTime.ToString(); } } private void cmdParent_Click(object sender, System.EventArgs e) { if (Directory.GetParent(lblCurrentDir.Text) != null) { string newDir = Directory.GetParent(lblCurrentDir.Text).FullName; lblCurrentDir.Text = newDir; ShowFilesIn(newDir); ShowDirectoriesIn(newDir); } } private void cmdBrowse_Click(object sender, System.EventArgs e) { if (lstDirs.SelectedIndex != -1) { string newDir = Path.Combine(lblCurrentDir.Text, lstDirs.SelectedItem.Text); lblCurrentDir.Text = newDir; ShowFilesIn(newDir); ShowDirectoriesIn(newDir); } } } }