We have a requirement to retrieve document library name based on the URL of a document library. We have searched through all the methods offered by "List" web service in SharePoint, but could not find any method that takes the URL of the document library as input and provides the document library name.
Appreciate any thoughts.
Thanks.
I don't think you can easily do it in a single line of code, but the following works with both URLs pointing directly to the document library as well as pointing to a file in that library
string completeUrl = "http://portal.dev.muhimbi.local/sites/PDFConverterTest/subsite2/Shared%20Documents";
using (SPSite site = new SPSite(completeUrl))
{
using (SPWeb web = site.OpenWeb())
{
SPList list = web.GetList(completeUrl);
string listName = list.Title;
}
}
Just to add to that, if you are looking for getting the Document library name from the Url, then it's best to use the object model. Once the document library is created, the url of the document library is fixed and therefore changing the name will not reflect in the url.
Related
The API that I need from the sharePoint is mention below:-
How to get all groups a user is a member of
Inside library permissions we have a setting to disable library data from appearing in Search, Below mention is the screenshot for which I am looking the api.enter image description here
It depends on the chosen technology, but generally:
SPUser object have the Groups property.
In CSOM:
var ctx = new ClientContext(url);
var user = ctx.Site.RootWeb.EnsureUser(userName);
ctx.Load(user.Groups);
ctx.ExecuteQuery();
https://learn.microsoft.com/en-us/dotnet/api/microsoft.sharepoint.spuser.groups?view=sharepoint-server#microsoft-sharepoint-spuser-groups
Use "NoCrawl" property from a SPList object.
https://learn.microsoft.com/en-us/dotnet/api/microsoft.sharepoint.splist.nocrawl?view=sharepoint-server#microsoft-sharepoint-splist-nocrawl
I’m trying to learn SharePoint Client Object Model, specifically how to get a list of all SharePoint site URLs using a remote connection. This is possible using webservices…but I want to do it using the client object model.
I’ve figured how to get the title lists of a specific sharepoint site using the following code:
client object module):
ClientContext ctx = new ClientContext( server );
ctx.AuthenticationMode = ClientAuthenticationMode.Default;
ctx.Credentials = WindowsAuthenticationCredentials(username, password);
Web w = ctx.Web;
var lists = ctx.LoadQuery(w.Lists);
ctx.ExecuteQuery();
//Enumerate the results.
foreach (List theList in lists)
{
}
Output:
Announcements, Master Collection Pages… etc…
How can I do the same to get a site url list?
In web services you can call the following to achieve that, but as I said just trying to figure out how to do the same using client object module. If you can provide c# code that would greatly be appreciated.
WSPSitedata.SiteData sitedata = new SiteData();
sitedata.Url = #SharePointBaseURL + #"_vti_bin/sitedata.asmx";
sitedata.Credentials = our_credentials
_sSiteMetadata metaData = new _sSiteMetadata();
_sWebWithTime[] webWithTime
sitedata.GetSite(out metaData, out webWithTime, out users, out groups, out vgroups);
The SharePoint Client Object Model CSOM is designed to remotly interact with your SiteCollection. Sure, it is possible to connect to various SiteCollections, but it's not possible to look over all SiteCollections sitting within a SPWebApplications.
In 2010 you could still use the ASMX WebServices which are available in earlier versions of SharePoint.
To get a better understanding of the CSOM you should have a look at the MSDN site http://msdn.microsoft.com/en-us/library/ee537247.aspx
Did you really mean a list containing all SiteCollection URLs or was that a misunderstanding?
Thorsten
Can anyone guide me for creating a Form library programmatically using C#.This is used for publishing infopath form. After creating the form library i need to add the fully trusted file(.xsn file) to the FORM’s FOLDER of that particular library.
Found here:
SPWeb web = ...
SPListTemplateType templateType = SPListTemplateType.XMLForm;
Guid listId = web.Lists.Add("MyFormLibrary", null, templateType);
SPList documentLibrary= web.Lists[listId];
This article shows how to upload a file.
Can't find much information on how to do this at all - how can I add in a web part and then configure the settings for it?
Here's a code snippet that will do that for you. In this example, I put a Content Editor Web Part on the page and set the content of it programmatically. If you want to find out what properties your web part has, you can manually put it on a page and export it. Examine the exported file for the property names.
In your case, must must reference the 3rd party DLL, and use the name on the desired web part instead of the ContentEditorWebPart. You can find out the name by either using the Object Browser or Reflector.
SPFile spPageFile = web.GetFile(targetFilePath);
using (SPLimitedWebPartManager theMan = spPageFile.GetLimitedWebPartManager(PersonalizationScope.Shared))
{
ContentEditorWebPart cewp = new ContentEditorWebPart();
cewp.ChromeType = PartChromeType.None;
XmlDocument xmlDoc = new XmlDocument();
XmlElement xmlEl = xmlDoc.CreateElement("NewCEWP");
xmlEl.InnerText = string.Format(#"<h2>Blah blah blah...</h2>");
cewp.Content = xmlEl;
theMan.AddWebPart(cewp, "Main", 0);
theMan.SaveChanges(wp);
}
Hope this helps.
Load the page you want to add the web part to via object model.
Get the SPLimitedWebPartManager for this page.
Add the web part you want via the AddWebPart() method.
If your web part uses the normal web part configuration then you can access the settings via the web parts properties.
Does anybody know how to programmatically update the content of any of the standard SharePoint v3 Web Parts?
As an example, put a Link Summary Web Part on a page. Add some links to it. Now, how can I update this information using the WSS API?
I have not found any direct way to do this, my only idea so far is to export the Web Part, (then delete it), modify the generated XML, and import it back. But surely, there must be an easier way?
You can use the SPLimitedWebPartManager class to manipulate Web parts on a Web part page. An instance of this class can be obtained from an SPFile object as follows:
using (SPSite site = new SPSite("<site url>")) // e.g. http://server/sites/asite
using (SPWeb web = site.OpenWeb())
{
SPFile file = web.GetFile("<page url>"); // e.g. /sites/asite/default.aspx
SPLimitedWebPartManager lwpm = file.GetLimitedWebPartManager();
SPLimitedWebPartCollection webParts = lwpm.WebParts;
WebPart wp = webParts[<id, index or Guid>];
// Add your code to update the Web Part
lwpm.SaveChanges(wp);
}
You can also add or delete web parts with the SPLimitedWebPartManager.
You will probably need to call SPWeb.GetWebPartCollection and use the webpart collection to mess with the WebParts thusly