Save File Dialog into Web Based Application http://forums.asp.net/t/1793902.aspx/1?Save+File+Dialog+into+Web+Based+Application+Fri, 27 Apr 2012 01:23:34 -040017939024937211http://forums.asp.net/p/1793902/4937211.aspx/1?Save+File+Dialog+into+Web+Based+Application+Save File Dialog into Web Based Application <p>Dear team :),</p> <p>I have a small problem. My case is that I am inserting some data into my Data Table, I need to export them into csv file. I could be able to write the code but I have a problem that the location of saving must be static. Is there anyway , same as WPF or Windows Forms, in ASP.net to let the user open save dialog and choose the path and even write the name?</p> <p></p> <p>Many thanks</p> 2012-04-17T17:33:20-04:004937220http://forums.asp.net/p/1793902/4937220.aspx/1?Re+Save+File+Dialog+into+Web+Based+Application+Re: Save File Dialog into Web Based Application <pre class="prettyprint">Response.ContentType = &quot;application/vnd.ms-excel&quot;; Response.AddHeader(&quot;content-disposition&quot;, &quot;attachment; filename=test.csv&quot;); Response.TransmitFile(Server.MapPath(&quot;~/Uploads/test.csv&quot;)); Response.End();</pre> <pre class="prettyprint">Refer this also</pre> <pre class="prettyprint"><a href="http://www.mindcracker.com/Story/496/how-to-download-pdf-file-using-Asp-Net">http://www.mindcracker.com/Story/496/how-to-download-pdf-file-using-Asp-Net</a></pre> <pre class="prettyprint">Hope this helps...</pre> 2012-04-17T17:40:30-04:004940172http://forums.asp.net/p/1793902/4940172.aspx/1?Re+Save+File+Dialog+into+Web+Based+Application+Re: Save File Dialog into Web Based Application <p>Hi</p> <p>I think first you can&nbsp;<span>generate the cvs file and save as a t<span>emporary file in your server-side temporary file folder .</span></span></p> <p>Tranfmit the file as attchment . while you download the file , then you can choose &nbsp;your save path and write the name.</p> <p><span><span>Assume you got a button when user click the button do this:</span></span></p> <pre class="prettyprint">Response.ContentType = &quot;Application/vnd.ms-excel&quot;;// these code write in the button click event Response.AppendHeader(&quot;Content-Disposition&quot;, &quot;attachment; filename=data.cvs&quot;); Response.TransmitFile(Server.MapPath(&quot;~/temp_files/data.cvs&quot;));//here server.mappath is your saved temp file[data.cvs] Response.End();</pre> <p><span><span><br> <br> </span></span></p> <p><span><span><br> </span></span></p> <p><span><span><br> </span></span></p> <p></p> <p><span><span>&nbsp;hope it hellps. if not , please let me know.</span></span></p> 2012-04-19T06:12:28-04:004942350http://forums.asp.net/p/1793902/4942350.aspx/1?Re+Save+File+Dialog+into+Web+Based+Application+Re: Save File Dialog into Web Based Application <p>Many thanks for your answer, below is what I currently have:</p> <p>when the user click on Save button, WrtieCSV function will be called but here the path is a static :(</p> <p>string path &nbsp;= &quot;F:\\MigrationFrom.csv&quot;;</p> <p>CreateCSVFile(MigrationResult, path); // MigrationResult is my data table and after filling it with data using Adapter</p> <p>&nbsp;public void CreateCSVFile(DataTable dt, string strFilePath){ // the Funtion</p> <p>}</p> <p>I need the path to be determined by a user as well as file name !</p> <p>so, you may give me another way, a better way of doing this :) especially that I also need an output in Differant formats i.e : xls, csv, .dbf or others.</p> <p>Here I also deal with around 2,000,000 records from Oracle database tables.</p> <p>Many thanks again&nbsp;</p> <p></p> 2012-04-20T07:44:56-04:004943036http://forums.asp.net/p/1793902/4943036.aspx/1?Re+Save+File+Dialog+into+Web+Based+Application+Re: Save File Dialog into Web Based Application <p>Hi,</p> <p>I think you can add a dropdownlist or combox control(item like:excel,word,pdf,dbf etc), then user can select the type of file, and add a textbox, user can write the name of the file (also path). in the code behind , when user click the button, you can get the value of dropdownlist and textbox, then you can dynamic set the type and the path of the file that you wanna save(here i got a question for you : do you really want to save the created file in server side? you got so many records!).</p> 2012-04-20T13:36:41-04:004943058http://forums.asp.net/p/1793902/4943058.aspx/1?Re+Save+File+Dialog+into+Web+Based+Application+Re: Save File Dialog into Web Based Application <p>Of course I DONT :), and for that I asked how can i let the user determine the path. it's not applicable to let the user write a path into a text box ! Come On!!! what I need is like when we browse to save a file, same as we want to download sth from any page. We usually select the path, then write the name.</p> <p></p> <p></p> 2012-04-20T13:52:04-04:004943116http://forums.asp.net/p/1793902/4943116.aspx/1?Re+Save+File+Dialog+into+Web+Based+Application+Re: Save File Dialog into Web Based Application <p>Hi,</p> <p>For security , based on my exerpience and research user can browse the server side file system. and&nbsp;Unfortunately my knowledge about save file in server side&nbsp;is incomplete, so what i can suggest you is : after the file been trasmit to user side then delete it.</p> <p></p> <p></p> <p></p> <p></p> <p>thanks</p> 2012-04-20T14:26:39-04:004943124http://forums.asp.net/p/1793902/4943124.aspx/1?Re+Save+File+Dialog+into+Web+Based+Application+Re: Save File Dialog into Web Based Application <p>mmm, so you suggest that I let the user save the file into server, then transmit the file into a location where can choose.</p> <p></p> <p>but I am really wondering ! I only need , like WPF or Windows Forms, sth such as Save file Dialog where I can get the path and even the name !</p> <p></p> <p>and I have a datatable with write function to write the data into csv file.</p> <p></p> <p>what do you think ?</p> 2012-04-20T14:30:09-04:004947521http://forums.asp.net/p/1793902/4947521.aspx/1?Re+Save+File+Dialog+into+Web+Based+Application+Re: Save File Dialog into Web Based Application <p>Hi,</p> <p>Base on my exerpience and research, you can create a save file folder in your Project, then user can save file into the folder. It is static path. And as far as I know, web application don't have something like WF Save File Dialog.</p> 2012-04-24T03:54:14-04:004947593http://forums.asp.net/p/1793902/4947593.aspx/1?Re+Save+File+Dialog+into+Web+Based+Application+Re: Save File Dialog into Web Based Application <pre class="prettyprint">private void DownloadFile(bool forceDownload) { string type = &quot;&quot;; // set known types based on file extension if (ext != null) { switch (ext.ToLower()) { case &quot;.htm&quot;: case &quot;.html&quot;: type = &quot;text/HTML&quot;; break; case &quot;.txt&quot;: type = &quot;text/plain&quot;; break; case &quot;.doc&quot;: case &quot;.rtf&quot;: type = &quot;Application/msword&quot;; break; case &quot;.xls&quot;: type = &quot;Application/x-msexcel&quot;; break; } } if (forceDownload) { Response.AppendHeader(&quot;content-disposition&quot;, &quot;attachment; filename=&quot; &#43; name); } if (type != &quot;&quot;) Response.ContentType = type; Response.AddHeader(&quot;Content-Disposition&quot;, &quot;attachment; filename=&quot; ); Response.WriteFile(path); Response.TransmitFile(strRolloverFilepath); Response.End(); }</pre> <p></p> <p></p> 2012-04-24T04:56:57-04:004949473http://forums.asp.net/p/1793902/4949473.aspx/1?Re+Save+File+Dialog+into+Web+Based+Application+Re: Save File Dialog into Web Based Application <p>Many thanks :) but...</p> <p></p> <p>How can I let the user determine the path !!!!!! in addition, where can i put my table adapter in the above code :D ?</p> <p></p> <p>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</p> <p></p> <p>Br,&nbsp;</p> 2012-04-24T21:13:40-04:004949936http://forums.asp.net/p/1793902/4949936.aspx/1?Re+Save+File+Dialog+into+Web+Based+Application+Re: Save File Dialog into Web Based Application <pre class="prettyprint">string FileName = Path.GetFileName(flUpdUpload.PostedFile.FileName); string Extension = Path.GetExtension(flUpdUpload.PostedFile.FileName); string FolderPath = ConfigurationManager.AppSettings[&quot;FolderPath&quot;]; string FilePath = Server.MapPath(&quot;~/UploadFiles/&quot; &#43; FileName); whereas Uploadfiles is a folder in my solution. u can have it or leave.try this</pre> <p></p> <p></p> 2012-04-25T06:32:21-04:004951634http://forums.asp.net/p/1793902/4951634.aspx/1?Re+Save+File+Dialog+into+Web+Based+Application+Re: Save File Dialog into Web Based Application <p><br> HOW CAN THE USER SELECT THE PATH !!!!!!!!!!!!!!!, how can he have such a browse window to select the path and write the name ?????</p> <p>Many thx&nbsp;</p> 2012-04-25T21:59:20-04:004953954http://forums.asp.net/p/1793902/4953954.aspx/1?Re+Save+File+Dialog+into+Web+Based+Application+Re: Save File Dialog into Web Based Application <p>Hi Wael Abu Rezeq,</p> <p>Browse server side file system, blow might help you.</p> <p>.aspx file</p> <pre class="prettyprint">&lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeBehind=&quot;WebForm19.aspx.cs&quot; Inherits=&quot;WebDev.WebForm19&quot; %&gt; &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt; &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt; &lt;head&gt;&lt;title&gt;test&lt;/title&gt;&lt;/head&gt; &lt;body&gt; &lt;form id=&quot;Form1&quot; method=&quot;post&quot; runat=&quot;server&quot;&gt; &lt;asp:ListBox id=&quot;lstDirs&quot; style=&quot;Z-INDEX: 101; LEFT: 32px; POSITION: absolute; TOP: 72px&quot; runat=&quot;server&quot; Width=&quot;248px&quot; Height=&quot;208px&quot; Font-Names=&quot;Verdana&quot;&gt;&lt;/asp:ListBox&gt; &lt;asp:Button id=&quot;cmdParent&quot; style=&quot;Z-INDEX: 109; LEFT: 176px; POSITION: absolute; TOP: 280px&quot; runat=&quot;server&quot; Text=&quot;Up One Level&quot; Width=&quot;100px&quot; Height=&quot;24px&quot;&gt;&lt;/asp:Button&gt; &lt;asp:Button id=&quot;cmdShowInfo&quot; style=&quot;Z-INDEX: 107; LEFT: 312px; POSITION: absolute; TOP: 280px&quot; runat=&quot;server&quot; Text=&quot;Show Info&quot;&gt;&lt;/asp:Button&gt; &lt;asp:Label id=&quot;Label2&quot; style=&quot;Z-INDEX: 104; LEFT: 312px; POSITION: absolute; TOP: 56px&quot; runat=&quot;server&quot; Width=&quot;192px&quot; Height=&quot;24px&quot; Font-Names=&quot;Verdana&quot; Font-Bold=&quot;True&quot; Font-Size=&quot;X-Small&quot;&gt;Contained Files:&lt;/asp:Label&gt; &lt;asp:ListBox id=&quot;lstFiles&quot; style=&quot;Z-INDEX: 102; LEFT: 312px; POSITION: absolute; TOP: 72px&quot; runat=&quot;server&quot; Width=&quot;280px&quot; Height=&quot;200px&quot; Font-Names=&quot;Verdana&quot;&gt;&lt;/asp:ListBox&gt; &lt;asp:Label id=&quot;Label1&quot; style=&quot;Z-INDEX: 103; LEFT: 32px; POSITION: absolute; TOP: 56px&quot; runat=&quot;server&quot; Width=&quot;216px&quot; Height=&quot;38px&quot; Font-Names=&quot;Verdana&quot; Font-Bold=&quot;True&quot; Font-Size=&quot;X-Small&quot;&gt;Subdirectories:&lt;/asp:Label&gt; &lt;asp:Label id=&quot;Label3&quot; style=&quot;Z-INDEX: 105; LEFT: 32px; POSITION: absolute; TOP: 16px&quot; runat=&quot;server&quot; Width=&quot;184px&quot; Height=&quot;19px&quot; Font-Names=&quot;Verdana&quot; Font-Bold=&quot;True&quot; Font-Size=&quot;Medium&quot;&gt;Current Directory:&lt;/asp:Label&gt; &lt;asp:Button id=&quot;cmdBrowse&quot; style=&quot;Z-INDEX: 106; LEFT: 32px; POSITION: absolute; TOP: 280px&quot; runat=&quot;server&quot; Text=&quot;Browse To Selected&quot; Width=&quot;136px&quot; Height=&quot;24px&quot;&gt;&lt;/asp:Button&gt; &lt;asp:Label id=&quot;lblFileInfo&quot; style=&quot;Z-INDEX: 108; LEFT: 312px; POSITION: absolute; TOP: 328px&quot; runat=&quot;server&quot; Width=&quot;280px&quot; Height=&quot;80px&quot; BorderStyle=&quot;Groove&quot; BorderWidth=&quot;2px&quot; Font-Names=&quot;Verdana&quot; Font-Size=&quot;X-Small&quot;&gt;&lt;/asp:Label&gt; &lt;asp:Label id=&quot;lblCurrentDir&quot; style=&quot;Z-INDEX: 110; LEFT: 240px; POSITION: absolute; TOP: 16px&quot; runat=&quot;server&quot; Width=&quot;184px&quot; Height=&quot;24px&quot; Font-Names=&quot;Verdana&quot; Font-Bold=&quot;True&quot; Font-Size=&quot;Medium&quot;&gt;&lt;/asp:Label&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p>.cs file</p> <pre class="prettyprint">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); } /// &lt;summary&gt; /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// &lt;/summary&gt; 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 = "&lt;b&gt;" + selFile.Name + "&lt;/b&gt;&lt;br&gt;"; lblFileInfo.Text += "Size: " + selFile.Length + "&lt;br&gt;"; lblFileInfo.Text += "Created: "; lblFileInfo.Text += selFile.CreationTime.ToString(); lblFileInfo.Text += "&lt;br&gt;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); } } } }</pre> <p><br> <br> <br> </p> 2012-04-27T01:23:34-04:00