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:
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?..
CS=65001
instead of109
. Here is an additional info in the article and comments: weblogs.asp.net/wkriebel/LinkToExportToSpreadsheet