Export Datatable to Excel 2010 format and Save in SharePoint Document library ,and whn opening file getting error "WorkBook may be in unsupported file format "

im converting stringwriter objec to Memory stream and saving this as .xlsx uploading file in library ,but when i try to open the file im getting error as below
WorkBook may be in unsupported file format
and when trying to open in excel getting message as
Excel cannot open file  because file extention or file format is not valid .verify thet the file has not been corrupted and file extensions match file format

May be you can use this approach:
http://www.c-sharpcorner.com/UploadFile/pandeypradip/export-data-into-excel-in-a-pre-defined-template-using-strea/

Similar Messages

  • Advice needed for provider hosted web application - authentication and access to SharePoint document library

    I haven't done SharePoint 2013 development with claims so I apologize in advance if my assumptions and questions are way out in left field.
    I'm trying to understand SharePoint 2013 claims authentication for a scenario that involves:
    A SharePoint provided hosted (web forms) app that will pull information and assets (e.g. PDFs) from SharePoint into the web page.
    It will be a VS 2012 solution with asp.net.identity feature.
    Security will be set for internal users, federated external users and forms-based external users.  Based on their security and (claim type) role it will define what information and assets that can be retrieved from SharePoint
    I have looked through MSDN and other sources to understand.
    This one helped with my understanding 
    Federated Identity for Web Applications and assumed that the general concept could be applied to forms-based identity for non-Federated external users .
    What I have now:
    VS 2012 solution web forms application set to Provider Host with asp.net.identity feature and its required membership tables.
    I can create new users and associate claims to the new user.
    I can log in with a user from the membership tables and it will take me to a default.aspx page.  I have added code to it that displays the claims associated to a user.
    For POC purposes I'd like to retrieve documents that are associated to this user from the default.aspx page.
    This is where I am having trouble understanding:  Is my understand correct?
    Internal users
    since they are internal on the network i am assuming that they would already have access to SharePoint and they would already be configured to what documents that they have available to them.
    Federated external users & Forms authentication external users
    it seems to me that the authentication for external users are separate from SharePoint authentication process.
    changes to the configuration settings are necessary in SharePoint, IIS, web application.
    I believe this is what i read.
    claims processes (e.g. mappings) need to be set up in SharePoint
    as long as external users are authenticated then things are ok b/c they would have claims associated to the user and the configuration in SharePoint takes are of the rest.
    This statement bothers me because I think it's wrong.
    So basically i'm stuck with if my understanding is correct: once a user is authenticated either by federated identity or asp.net.identity authentication that it should go to the provider hosted default.aspx page because the claim is authenticated and means
    that it should have access to it and the SharePoint document library based on some claim property.  I could then write the calls to retrieve from a document library and SharePoint will know based on some claim property that the logged in user can only
    access certain documents.
    It just sounds too good to be true and that i'm missing something in the thought process.
    Thanks in advance for taking the time to read.
    greenwasabi

    Hi GreenWasabi,
    i agree this is an interesting topic to discuss,
    as you can check from the article, you may check this example from the codeplex:http://claimsid.codeplex.com/
    when i thinking regarding this topic, its looks like an environment with multiple of realms,
    from what you understand, its correct that all the authentication is based from the provider, so for example i have a windows live ID and internal ID, then when i login windows live ID, it will be authenticated using windows live ID server.
    here is the example for the webservice:
    http://claimsid.codeplex.com/wikipage?title=Federated%20Identity%20for%20Web%20Services&referringTitle=Home
    as i know, if you using this federated, i am not quite sure that you will need to go to the provider page literally, perhaps you can check this example if we are using azure:
    http://social.technet.microsoft.com/wiki/contents/articles/22309.integrating-windows-live-id-google-and-facebook-accounts-with-sharepoint-2013-white-paper.aspx
    Regards,
    Aries
    Microsoft Online Community Support
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

  • How to get the count of items(folders or documents) in a SharePoint document library and for a folder in any SharePoint document library?

    I need to get a count of documents and folders in a selected document library(the item for EventRecievers for event deleting) and the count of documents in a selected folder(the item for EventRecievers for event deleting) to determine whether the item(document
    library or folder) is empty or not, as I need to use this condition for one of my custom EventReceivers.
    Can you please suggest me the code to do the same?

    Hi.
    Try this:
    class Program
    static void Main(string[] args)
    using (SPSite site = new SPSite("http://z2012net"))
    using (SPWeb web = site.OpenWeb())
    SPList l = web.Lists["List001"];
    List<FolderInfo> res = new List<FolderInfo>();
    getListCount(l.RootFolder, ref res);
    private static void getListCount(SPFolder sPFolder, ref List<FolderInfo> res)
    SPQuery query = new SPQuery();
    query.Folder = sPFolder;
    res.Add(new FolderInfo() { ItemCount = sPFolder.ItemCount, Name = sPFolder.Name, Url = sPFolder.Url });
    SPListItemCollection items = sPFolder.ParentWeb.Lists[sPFolder.ParentListId].GetItems(query);
    foreach (SPListItem item in items)
    if (item.FileSystemObjectType == SPFileSystemObjectType.Folder)
    SPFolder f = sPFolder.ParentWeb.GetFolder(item.UniqueId);
    getListCount(f, ref res);
    class FolderInfo
    public string Url { get; set; }
    public string Name { get; set; }
    public int ItemCount { get; set; }
    Regards,
    Bubu
    http://zsvipullo.blogspot.it
    Please mark my answer if it helped you, I would greatly appreciate it.

  • How to fetch folders and subfolders from sharepoint document library

     I have document library with name . Under "Documents" there are some folders.Under some folders there are some subfolders.
    I need to fetch the folders in to dropdown list. IF I select some folder in dropdownlist,I need to fetch subfolders of that folder to some other dropdownlist.
    How to acheive this

    The below function get the folder name and id of subfolder where items stored folder = item.folder.  Initially it will be null.
    static
    string GetParentFolder(SPListItem itemToFind,
    SPFolder folder) 
    SPQuery query =
    new SPQuery();
    query.Query = "<Where><Eq><FieldRef Name=\"ID\"/><Value Type=\"Integer\">"+ itemToFind.ID +"</Value></Eq></Where>";
    query.Folder = folder;
    query.ViewAttributes = "Scope=\"Recursive\"";
    SPListItemCollection items = itemToFind.ParentList.GetItems(query);
    int intpartentFolderID=0 ;
    if (items.Count > 0)
    foreach (SPListItem item
    in items)
    SPFile f = item.Web.GetFile(item.Url);
    string test11 = f.ParentFolder.Name;
    intpartentFolderID = f.ParentFolder.Item.ID;
    return (intpartentFolderID.ToString());
             return (intpartentFolderID.ToString());    

  • Create an excel and upload it in document library through c#

     Hi everyone,
       I have one requirement in my organization . pickup data from multiple lists from sharepoint silte and convert it as an excel spredsheet and save it to the document library in c# progamming
     Can any one help me 
    Thanks 
    Nag

    Hi Nag,
    Per my understanding, you might want to gather data from multiple lists, generate an Excel file and save to a Document Library using C#.
    There will be several steps in this scenario: get data from SharePoint List using SharePoint Object Model, create an Excel file and save to a Document Library, then
    access this Excel file with the help of Excel Web Services.
    About the retrieving data from a SharePoint list, we can use SharePoint Object Model:
    SharePoint Object Model - SPListItem class
    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splistitem.aspx
    Add, Update and Delete List Items Programmatically in SharePoint
    http://www.mindfiresolutions.com/Add-Update-and-Delete-List-Items-Programmatically-in-Sharepoint-372.php
    About how to create document in a SharePoint library programmatically:
    https://nickgrattan.wordpress.com/2008/12/08/code-for-creating-new-documents-based-on-a-content-type-and-template/
    About how to work with Excel web Services: 
    https://msdn.microsoft.com/en-us/library/office/ms572330(v=office.15).aspx
    https://msdn.microsoft.com/en-us/library/office/ff640648(v=office.14).aspx
    Best regards
    Patrick Liang
    TechNet Community Support

  • Detect what the default edit form is for a document library and list using jquery

    Hi,
    So what I have done is with some jquery made it that when a files are dragged and dropped into a document library and there is a required field such as "Metadata" the EditForm.aspx opens up for the user to fill in the required column. I am building
    the url up from what I have found in SharePoints DragDrop.js file. This is all working perfectly I just need to find a way to dynamically find what the default edit form is for that document library as I have just hardcoded like this...
    g_currentControl.strSiteUrl + "/" + this.ListName + "/Forms/EditForm.aspx?ID=" + id
    So I need a way to figure out what the default edit form is instead of hard coding like this in case someone creates a custom_editform.aspx or something for one of the lists.
    Thanks

    You can get it by hitting this REST end point via JQuery:
    http://weburl/_api/Web/Lists(guid'YOURLISTGUID')/Forms
    Chris Givens CEO, Architecting Connected Systems
    Blog Twitter

  • How to reserve the page size when exporting to MS Excel 2010

    Hello. I have a report which exports to MS Excel 2010. I applied the page size as legal in Crystal Report and would like to use the same page size in Excel
    However, MS Excel print preview says the page size is letter.
    How could I keep the same page size in Excel as I applied in Crystal Report. We have a lot of business reports and would like to avoid applying page setting manually in Excel when users print them out each time.
    Thank you.

    Hi Christine
    I am in the process of writing a doc on the different options in CR and the "No Printer" option sis one of those. Seeing this post, made me wonder as this looked like a questionable behavior. My testing does not support your observations. Now, I did a very simple test;
    Created a report, set "No Printer", set the paper size and legal orientation. Exported to XLS - any format, and the export maintained legal paper size in all instance. I did a few other variations, but I can never get the report to export anything other than Landscape.
    Can you  please let me know the version of CR you are using?
    You may also want to attach the report here with saved data (to attach rename the rpt to txt, then in the reply hit on the "Use advanced editor" link and attach.
    BTW.; I am using CR 2013.
    - Ludek
    Senior Support Engineer AGS Product Support, Global Support Center Canada
    Follow us on Twitter

  • Can I capture a picture with my ipad, and save it as a PNG and/or SVG file to a specific folder?

    Can I capture a picture with my ipad, and save it as a PNG and/or SVG file to a specific folder?

    Kind of, sort of. (You can't save as SVG, but you can export as PNG.) PS Touch projects themselves are self-contained UNTIL they are exported, and even then they'll get exported to a specific location. (e.g., To the Camera Roll or Gallery/Photos, to Creatve Cloud, etc.)
    The procedure would be to start a new project using the "add image" icon (looks like a landscape with a plus sign, in the lower right in the project selection user interface) > Camera. Take your picture, then PS Touch will bring you to the editing user interface. Edit your image as appropriate.
    Go back out to the project selection user interface by tapping the back arrow in the upper left to save. You can then export the project using the export icon (5th icon from the upper right).

  • How to read excel file in document library and store excel content in sql table

    Hello,
    Can anyone help me how to read the excel file present in document library and store the content inside excel into sql table?
    Please let me know the ways to acheive this. Feel free to give your suggestions.
    Thanks,
    Cool Developer

    Hi!
    this code i have written becuase i donot find any soltions on net for this , u can try with this . :)
    System.Data.OleDb.
    OleDbConnection ExcelConnection = null;
    FileMode fileMode;
    string filePath = ConfigurationManager.AppSettings["TempLoaction"] + "\\" + fileName;
    using (SPSite _site = new SPSite(SPContext.Current.Web.Url))
    using (SPWeb _web = _site.OpenWeb())
    string docLibrary = ConfigurationManager.AppSettings["DocumentLibrary"];
    SPFile _file = _web.GetFile("/" + docLibrary + "/" + fileName);
    fileMode =
    FileMode.Create;
    byte[] byteArray = _file.OpenBinary();
    MemoryStream dataStream = new MemoryStream(byteArray);
    Stream stream = dataStream;
    using (FileStream fs = File.Open(filePath, fileMode))
    byte[] buffer = new byte[4096];
    int bytesRead;
    while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) != 0)
    fs.Write(buffer, 0, bytesRead);
    fs.Close();
    //Create the Connection String
    try
    string ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;
    Data Source ='"
    + filePath + "'; Extended Properties=Excel 5.0";
    //Create the connection
    ExcelConnection =
    new System.Data.OleDb.OleDbConnection(ConnectionString);
    //create a string for the query
    string ExcelQuery;
    //Sheet1 is the sheet name
    //create the query:
    //read columns from the Excel file
    ExcelQuery =
    "Select * from [Sheet1$]"; // from Sheet1";
    //use "Select * ... " to select the entire sheet
    //create the command
    System.Data.OleDb.
    OleDbCommand ExcelCommand = new System.Data.OleDb.OleDbCommand(ExcelQuery, ExcelConnection);
    //Open the connection
    ExcelConnection.Open();
    //Create a reader
    System.Data.OleDb.
    OleDbDataReader ExcelReader;
    ExcelReader = ExcelCommand.ExecuteReader();
    //For each row after the first
    while (ExcelReader.Read())
    thanks,
    kshitij

  • HT4059 When I have a PDF that I want to open and save into iBooks - it will attempt to open it and the shelf flips around to make room for it. But it doesn't save it. I have to end up opening it in Adobe or Kindle app to view & save it.

    When I have a PDF that I want to open and save into iBooks - it will attempt to open it and the shelf flips around to make room for it. But it doesn't save it. I have to end up opening it in Adobe or Kindle app to view &amp; save it. This has been doing this awhile, what's wrong. Should
    I take it and have it looked at?

    is there any important stuff saved to your emails? if so you could log on to your emails from a seperate device and back them up. im not sure what else you could do :/

  • How do I edit and save a word document that has been e-mailed to my ipad

    How do I edit and save a word document that has been e-mailed to my ipad and then re-send

    Use the paid version (install and activate) of Microsoft Word.
    https://itunes.apple.com/sg/app/microsoft-word-for-ipad/id586447913?mt=8

  • Can't use 'save' and 'save as' in Id, Ia and Ps.

    I can't use 'save' and 'save as' in Id, Ai and Ps. The window flips away. I've got Adobe CC. The Dutch version.

    Yes, it's executable; it tries to execute either way.
    The Unix LF through Smultron seemed to work. However, I don't see such an option in nano - only Mac and DOS. (I'm not too concerned, I'm pretty sure I"ll use Smultron on a regular basis to edit these files.)

  • Error while Open and save pdf using Adobe library

    I m using adobe library to open and save PDF using VC++ MFC .
    as given samples are working for me all are using console application to accomplish this task.
    But when i tried to use same functions to open and save PDF from DOC/VIEW application it gives me an error.
    it is a strange problem that I don't understand. If I compile the following code (Visual C++ 2000 Express Edition) I get an error message: "Unhandled exception at 0x0041183f in test.exe: 0xC0000005: Access violation reading location 0x00000004."
    For your reference when I simply  create one function and one menu and called that function from menu.
    Please see the code is given below.
    The code is given below
    void CPDF_MFCDoc::OnPdfOpen()
        // TODO: Add your command handler code here
        OpenPDF();
    #define PDF_FNAME1  "C:/Test.pdf"
    void OpenPDF()
         PDDoc pdDoc= NULL;
         ASErrorCode errCode = 0;
         DURING
            pdDoc1 = MyPDDocOpen(PDF_FNAME1);
        HANDLER
            errCode = ERRORCODE;
        END_HANDLER
    It gives me an error as.
    Unhandled exception at 0x004075b1 in PDF_MFC.exe: 0xC0000005: Access violation reading location 0x00000024.
    But when same thing I was complied from console ,it works.
    Working code is given below.
    #define PDF_FNAME1  "C:/Test.pdf"
    void MainProc(int argc, char **argv )
         PDDoc pdDoc= NULL,
         ASErrorCode errCode = 0;
         DURING
                 pdDoc1 = MyPDDocOpen(PDF_FNAME1);
         HANDLER
            errCode = ERRORCODE;
        END_HANDLER
    PDDoc MyPDDocOpen(char *fileName)
        ASFileSys asFileSys = ASGetDefaultFileSys();
        volatile ASPathName asPathName    = NULL;
        volatile PDDoc        pdDoc        = NULL;
        DURING
            /* Create asPathName from file.*/
            #if MAC_PLATFORM
            asPathName = GetMacPath(fileName);
            #else
            asPathName = ASFileSysCreatePathName(asFileSys, ASAtomFromString("Cstring"), fileName, 0);
            #endif
            /* Open pdDoc from asPathName.*/
            pdDoc = PDDocOpen(asPathName, NULL, NULL, true);
            fprintf(stdout, "Successfully opened %s\n", fileName);
        HANDLER
            fprintf(stderr, "Unable to open %s\n", fileName);
            pdDoc = NULL;
        END_HANDLER
        /* Release asPathName.*/
        if (asPathName)
            ASFileSysReleasePath(asFileSys, asPathName);
        return pdDoc;

    Yes ,I have it , I think when i tried to open or save any document "ASGetDefaultFileSys()" function not able to get file it raise an error , can you please help me out . where I m wrong.
    Why this "ASGetDefaultFileSys()" function raise as "Access violation error" .
    Please help me.

  • How do document permissions differ from its document library and a content roll-up webpart?

    I have an excel spreadsheet (a group schedule), in a document folder, on a page that only IT management can see/access/edit, in a site that all IT group members have access to.
         for example: http://IT Group site/IT Management Page/Schedule/2015.xlsx
    On the group's homepage, I have a content roll-up web part that displays all document library contents in the group site.
    IT management consists of 3 people. They can all edit the spreadsheet from the original location, but when they access the document from the content roll-up web part on the group's homepage, they cannot save any changes.
         Accessing the file from here: http://IT Group site - content roll-up web part link "2015.xlsx" points to "IT Group site/IT Management Page/Schedule/2015.xlsx"
    The error received says "'http://IT Group site/IT Management Page/Schedule/2015.xlsx' is read-only. To save a copy, click OK, then give the workbook a new name in the Save As dialog box."
    Where would the permission issue be?
    As the SharePoint site owner, I can access the file without any problems saving from either location. Also, I created an IT Management group that has full control over the IT Group site/IT Management Page, and full control over the IT Group site.
    Thanks for any info you can share.
    Stephanie

    Thanks Cameron -
    I have no special settings on the document library where the schedule is saved. No content approval necessary or different permissions. The library is set to open documents in client application, and check-in, check out is not activated.
    I have logged in to one of their computers. They can access the spreadsheet directly from the document library and make changes freely, and save that version directly to the server, but not from any web parts. Just to test, I created a summary link web part
    on the same page that lists the document library, created a link to the file, and the file opens, but they cannot save any changes without renaming the file. The only place they can truly edit the spreadsheet without renaming is from the document library
    directly.

  • How to add User Permissions to form created in InfoPath 2010 created for SharePoint document Library

    Hi,
    I created a form in InfoPath 2010 with three views (one for user input, the other two views to be used by supervisors) and published this to a SharePoint 2010 document library. Now the way this form is supposed to work is that when a User goes to the document
    library and adds a document, it is supposed to open the Form with the User's input view. When the User submits the document, only him/her should be able to open and possibly edit the the form. When the Immediate Supervisor opens the form, it should open in
    the Supervisors view and allow them to fill in only their section and not be able to edit or alter the user's data. When the Immediate Supervisor saves the document, the Over-all Supervisor should be able to open it in their view and not be able to edit or
    alter the sections filled out by the User and Immediate Supervisor.
    How would i go about completing this? I have the views created but now have the problem of associating these views with their respective users or groups.

    Hello,
    You need to first create user group in sharepoint site then add user in group according to their role. Later you need to call usergroup.asmx web service to get current logged-In user group name so you can switch view and also apply rule for editing or disabling
    controls in form.
    Follow this link to get group name:
    http://social.technet.microsoft.com/wiki/contents/articles/13271.sharepoint-2010-extracting-user-group-of-current-login-user-in-infopath-2010.aspx
    http://social.msdn.microsoft.com/Forums/en-US/018f5184-5c83-4a53-b66b-8c376fc800fc/how-to-get-current-users-sharepoint-group-name-sharepoint-2010-infopath-2010
    To apply rule on control:
    http://office.microsoft.com/en-in/infopath-help/add-rules-for-performing-other-actions-HA101783373.aspx
    Hope it could help
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

Maybe you are looking for

  • Real time data aquisation(RDA)

    hi if i want use datasource for RDA , its support in r/3 side? so its wont support for flat file? where can i check  the data source will support for RDA or not? once datasource replicated while creating infopackage need to check check box and dtp ne

  • The Mysterious aTV Buffering Issue: Can it be solved?

    Hey guys, I’m really stumped here so I’m hoping someone has a clue as to what’s going on. Here’s the deal. I’ve been ripping my DVD’s using MTR and Visual Hub. Everything looks amazing my my Apple TV. Couldn’t be happier. ...until I ripped season 1 o

  • Alt/Option Key gets registered with any key I type. How can I fix

    Hello, Today I encountered an issue. Suddenly my macbook air is typing everything as if the alt/option key was stuck. When I display keyboard viewer I realize that it is not being registered as being pressed. However, as soon as I press any key all t

  • Can't access iPhoto 09 library from outside iPhoto

    Since upgrading to iLife 09 I can't access my iPhoto library from anywhere BUT iPhoto. I use Photoshop CS2 and open my photos directly from that application. But now when the directory actually appears, it is greyed-out and inaccessible.

  • How do I enter passcode in voice over mode?

    Hi, Don't know I did it, but I activated voice over mode on Ipad 1. Now can;t enter passcode. Any help appreciated.