0

I want to create a button that exports specific list into the excel file. But when I do it I always get the same error:

Error List does not exist. The page you selected contains a list that does not exist. It may have been deleted by another use

How can it be possible? List exists, because I get id from object model so I should get a NullReferenceException otherwise. Here is my code:

<input type="button" onclick="window.location.href='<%= ExcelUrl %>';" value ="Export data"/>

code:

    protected override void OnPreRender(EventArgs e)
    {
        string listName = Lang.Localize("xxx", "List_Measures");
        using (var site = new SPSite(SPContext.Current.Site.ID))
        using (var web = site.OpenWeb(SPContext.Current.Web.ID))
        {
            var list = web.Lists[listName];
            const string relativeUrlMask = @"_vti_bin/owssvr.dll?CS=109&Using=_layouts/query.iqy&List={0}&View={1}&CacheControl=1";                
            ExcelUrl = new Uri(new Uri(site.Url), string.Format(relativeUrlMask, list.ID.ToString("B"), list.DefaultView.ID.ToString("B"))).AbsoluteUri;
        }
        base.OnPreRender(e);
    }

finally I get an url:

http://mysite/_vti_bin/owssvr.dll?CS=109&Using=_layouts/query.iqy&List=%7B27f5c5b6-e01d-4951-8be5-b31a72eda0e2%7D&View=%7Be518453d-c622-4f31-a0e7-09179f67dce3%7D&CacheControl=1

and it throws this exception. How make it work?


usage of web.Url instead of site.Url doesn't work


Now i get correct url, but have another problem: it says that I have not enough permissions event if I'm logged under System account. How can it be actually possible?..

4
  • If you copy the URL in browser address bar, does it work then? Commented Jul 6, 2015 at 11:50
  • I found the answer, First of all, current web returns parent web, but not actual. Second - should use CS=65001 instead of 109. Here is an additional info in the article and comments: weblogs.asp.net/wkriebel/LinkToExportToSpreadsheet Commented Jul 6, 2015 at 11:58
  • 1
    So it was a survey list. Anyways, one way to check how out of the box export to excel works is by trapping the network traffic using fiddler and use that Url to build one for your application. Commented Jul 6, 2015 at 12:02
  • I've got it, but thanks for an advice :) Commented Jul 6, 2015 at 12:04

2 Answers 2

0

if you are working with Sharepoint2013 than 2013 provide out of the box service to export sharepoint list to Exel or Access. I have refer This one , you can also try it .

https://www.microsoftpressstore.com/articles/article.aspx?p=2224034&seqNum=2

0

Instead of exporting from SharePoint, you can try importing from Excel through add-ins like http://www.cdata.com/drivers/sharepoint/excel/ (commercial). The Excel Add-in allows you to connect to Sharepoint lists, and filter data through transact SQL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.