none
Infopath Browser Form using C# to download as CSV to local drive RRS feed

  • Question

  • Hello,

    Currently, I have a button which extracts fields from the form into a string and saves as a CSV file using Save File Dialog Box. However, this doesn't work in the browser. When I upload the form, I get the error message, "User Interface Options are not supported".

    saveFileDialog1.Filter = "CSV files (*.csv)|*.csv|All files (*.*)|*.*";
    saveFileDialog1.FilterIndex = 1;
    saveFileDialog1.DefaultExt = ".csv";
    saveFileDialog1.FileName = filename.ToString();
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    System.IO.File.WriteAllText(saveFileDialog1.FileName, temp.ToString());
                 }
    Is there another way to save a string as a CSV file onto a user's local drive?
    Tuesday, March 31, 2020 4:27 PM

All replies

  • Hi mattg557,

    Thank you for posting here.

    Savefiledialog is a control of winform, but you mentioned the browser, is your project an ASP project?

    If this is the case, errors are normal, because savefiledialog is not available for the web.

    If you need to implement similar functions, you can refer to the following code.

    System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
    response.ClearContent();
    response.Clear();
    response.ContentType = "text/plain";
    response.AddHeader("Content-Disposition", "attachment; filename=" + filePath + ";");
    response.TransmitFile(filePath);
    response.Flush();
    response.End();

    If I understand you wrong, please let me know.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, April 1, 2020 2:35 AM
  • Thanks Timon! Is there any way to download the file without saving it on the server?
    Wednesday, April 8, 2020 8:58 PM
  • Hi mattg557,

    There is a solution written in Javascript, see if it can solve your problem


    Loading, Editing, and Saving a Text File in HTML5 Using Javascript

    In addition, questions about ASP.NET can be asked in the ASP.NET forum, they are more familiar with it.

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; Therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, April 9, 2020 6:35 AM