locked
issue with filepath in fileupload control RRS feed

  • Question

  • Hi,

    I am using fileupload contrl to upload an xlsx file and read it in datatable


    filepath = Server.MapPath(fileUploadExcel.FileName);

    connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filepath + "; Extended Properties=Excel 12.0";

    the above code gives me the connection string as below

    Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\A.B\Documents\Visual Studio 2015\Projects\Test.SharePoint.Tools\Test.SharePoint.ToolsWeb

    \Sheet.xlsx; Extended Properties=Excel 12.0


    I want the connection string as below:
    Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\A.B\Desktop\sheet.xlsx; Extended Properties=Excel 12.0

    what wrong i am doing or is there any way to get the path in the way i want.
    It basically is taking path from the location where my control is and not from the actual location.

    any suggestions?

    Friday, February 26, 2016 10:25 AM

Answers

  • Hi,

    Please replace the following line of code

    filepath = Server.MapPath(fileUploadExcel.FileName);

    To

    filepath = fileUploadExcel.PostedFile.FileName;

    Best Regards,

    Dennis


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    • Proposed as answer by Patrick_Liang Wednesday, March 2, 2016 8:43 AM
    • Marked as answer by Patrick_Liang Friday, March 4, 2016 11:08 AM
    Monday, February 29, 2016 3:02 AM

All replies

  • Hi,

    Please replace the following line of code

    filepath = Server.MapPath(fileUploadExcel.FileName);

    To

    filepath = fileUploadExcel.PostedFile.FileName;

    Best Regards,

    Dennis


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    • Proposed as answer by Patrick_Liang Wednesday, March 2, 2016 8:43 AM
    • Marked as answer by Patrick_Liang Friday, March 4, 2016 11:08 AM
    Monday, February 29, 2016 3:02 AM
  • i got to know we cannot use filepath in 0365 as it gives server side path.

    To read an excel file at client side we can use fileupload.filecontent and then deal with it

    Tuesday, March 8, 2016 12:18 PM