Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11571

web part tool pane properties to have a property where user can change list guid(Please refer the code below)

$
0
0

I need to create a property in web part tool pane like a text box  where user can add a list guid in the property window so that user can change the list guid which can be applied..Please find the code below where i am getting list guid i applying.Please help me through the code where to add property and apply it.

protected void btnsubmit_Click(object sender, EventArgs e)

{

if (RelinkDocuments())

{

Label3.Text =

"Success!!!";

}

else

{

Label3.Text =

"Failure";

}

}

private bool RelinkDocuments()

{

try

{

SPSite site = SPContext.Current.Site;

SPWeb spWeb = site.OpenWeb();

SPList spList = spWeb.Lists[new Guid("89023C18-DBA3-4843-81B7-E034111544BC")];

SPDocumentLibrary doclib = (SPDocumentLibrary)spList;

string solutionUrl = SPHttpUtility.UrlPathEncode(spWeb.Url + "/" + doclib.DocumentTemplateUrl, true);

foreach (SPListItem spItem in doclib.Items) //loop through the list items

{

SPFieldCollection spFields = spItem.Fields;

foreach (SPField spField in spFields) //loop through fields resetting them

{

if (spField.Type != SPFieldType.Computed &&

spField.Type !=

SPFieldType.Invalid && !spField.ReadOnlyField)

{

try

{

spItem[spField.InternalName] = spItem[spField.InternalName];

}

catch (Exception e)

{

}

}

}

SPContentType spContentType = spList.ContentTypes[(SPContentTypeId)spItem["ContentTypeId"]];

if (spContentType != null) //try to update the item with the content type's template url which is the updated one

{

if (spContentType.DocumentTemplate.StartsWith("http://") ||

spContentType.DocumentTemplate.StartsWith(

"https://"))

{

spItem[

"TemplateUrl"] = SPHttpUtility.UrlPathEncode(spContentType.DocumentTemplate, true);

}

else if (spContentType.DocumentTemplate.StartsWith("/"))

{

spItem[

"TemplateUrl"] = SPHttpUtility.UrlPathEncode(spWeb.Site.MakeFullUrl(spContentType.DocumentTemplate), true);

}

else

{

spItem[

"TemplateUrl"] = SPHttpUtility.UrlPathEncode(spWeb.Url + '/' + spList.RootFolder + '/' + spContentType.DocumentTemplate, true);

}

}

else //no content type found so default template url to solution Url

{

spItem[

"TemplateUrl"] = solutionUrl;

}

spItem.Update();

}

return true;

}

catch (Exception ex)

{

return false;

}

}

 

}

}


Viewing all articles
Browse latest Browse all 11571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>