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"/>


    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;

finally I get an url:


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?..

  • If you copy the URL in browser address bar, does it work then? 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 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. Jul 6, 2015 at 12:02
  • I've got it, but thanks for an advice :) Jul 6, 2015 at 12:04

2 Answers 2


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 .



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.