I have a library with internal name "LiteracyResources" and the display name was updated to "Literacy Resources" (a space between two words). I need to bind documents to a grid and click on name I need to download it. Simple requirement.
The issue I face was when I try to get list I need to use name with space. And If I want to get any file url for download, I need to create it and that should use internal name of the list. Otherwise your download url won't work.
So to get internal name of list, I use "list.RootFolder.Name".
below is the code that I use for this:
Code:
SPList resourcelist = null;
using (SPSite siteCol = new SPSite(SPContext.Current.Site.Url))
{
SPWeb web = siteCol.RootWeb;
{
SPList list = web.Lists.TryGetList(Constants.LibNameLiteracy); // Here we need to //use library name with space
SPListItemCollection items = list.GetItems();
if (items.Count > 0)
{
dt = items.GetDataTable();
dt.Columns.Add(Constants.ColNameDocURL, typeof(string));
for (int itemcount = 0; itemcount < dt.Rows.Count; itemcount++)
{
if (web.Url.EndsWith("/"))
{ // here we use internal name
dt.Rows[itemcount][Constants.ColNameDocURL] = web.Url + list.RootFolder.Name + "/" + Convert.ToString(dt.Rows[itemcount][Constants.ColNameFileLeafRef]);
{
else {
dt.Rows[itemcount][Constants.ColNameDocURL] = web.Url + "/" + list.RootFolder.Name + "/" + Convert.ToString(dt.Rows[itemcount][Constants.ColNameFileLeafRef]);
}
dt.AcceptChanges();
}
}
}
}
allYearsGrid.DataSource = dt;
allYearsGrid.DataBind();