Create Document Library using Client Object Model - sharepoint

Just a quick question, is it possible to create a Document Library using the Client Object Model in SharePoint 2010?
I know you can create lists etc. Am I right in saying that a Document Library is just a 'special' type of List?
How can I specify that the List I create will be a Document Library?
Any help will be appreciated
Thanks

Yes. You can specify the TemplateType for your List.
List of TemplateTypes
using (ClientContext clientCTX = new ClientContext(url))
{
ListCreationInformation lci = new ListCreationInformation();
lci.Description = "My own DocLib";
lci.Title = "Library";
lci.TemplateType = 101;
List newLib = clientCTX.Web.Lists.Add(lci);
clientCTX.Load(newLib);
clientCTX.ExecuteQuery();
}

You can also set the templatetype with the following code, which I think makes things clearer to new programmers:
lci.TemplateType = (int) ListTemplateType.DocumentLibrary;

Related

Sharepoint C# How to retrieve all pictures and their name by Title of Picture library

Who knows about how to get the image by the Title of the Picture Library (List) using SP C #. Can guide me.
Hope everybody know about SharePoint can help me.
Thanks so much.
You can use CSOM to achive this, demo code is here: https://www.codesharepoint.com/csom/get-all-items-in-sharepoint-using-csom
using Microsoft.SharePoint.Client;
using (ClientContext clientContext = new ClientContext("http://MyServer/sites/MySiteCollection"))
{
// clientcontext.Web.Lists.GetById - This option also can be used to get the list using List GUID
// This value is NOT List internal name
List targetList = clientContext.Web.Lists.GetByTitle("List Name");
// Optioanlly you can use overloaded method CreateAllItemsQuery(int rowlimits, params viewfields): where using "rowlimits" you can limit the number of rows returned and viewfields will return only specified fields in the result set
// This method will get all the items from all the folders and sub folders including folders and sub folders too
CamlQuery oQuery = CamlQuery.CreateAllItemsQuery();
ListItemCollection oCollection = targetList.GetItems(oQuery);
clientContext.Load(oCollection);
clientContext.ExecuteQuery();
foreach (ListItem oItem in oCollection)
{
Console.WriteLine(oItem["Title"].ToString());
}
}

Why does "ElementId(BuiltInCategory.OST_Walls)" fails within Revit API 2019?

I am trying to filter walls. For that I use
categories = List[ElementId]()
myId = ElementId(BuiltInCategory.OST_Walls)
categories.Add(myId)
..but this obviously doesn't return a valid ElementId, as when I print it, it has some negative value (and if I print "doc.GetElement(myId)", I get "None").
Then, indeed when creating the filter...
filter = ParameterFilterElement.Create(doc, "Walls filter", categories)
...I get an ArgumentException.
I'm using Revit 2019 (with pyRevit). As far as I remember, it used to work with Revit 2018, but I don't see any reason it shouldn't anymore. What am I missing?
Thanks a lot!
You can simply use the filtered element collector OfCategory Method.
E.g., check out The Building Coder hints on filtered element collector optimisation.
Apply an ElementCategoryFilter to the collector to get all the walls of the project. By using the following code you can filter any kind of category. I have tried this on Revit 2019.
FilteredElementCollector collector = new FilteredElementCollector(document);
ICollection<Element> walls = collector.OfCategory(BuiltInCategory.OST_Walls).ToElements();
I agree with #Mah Noor answer.
If you need to have a filter with multiple categories, you can use:
ElementCategoryFilter wallFilter = new ElementCategoryFilter(BuiltInCategory.OST_Walls);
ElementCategoryFilter windowFilter = new ElementCategoryFilter(BuiltInCategory.OST_Windows);
LogicalOrFilter wallAndWindowFilter = new LogicalOrFilter(wallFilter, windowFilter);
ICollection<Element> collection = new FilteredElementCollector(doc).WherePasses(wallAndWindowFilter);
Bonus tip, you may want to add .WhereElementIsNotElementType() or .WhereElementIsElementType() to your query.
Best regards
François

How to extract lists from Sharepoint which includes the attacthments

Any idea's on how to extract a list (not Library's) from Sharepoint that includes the attachments.
When i extract to excel the attachments column just says YES or NO but no actual copy or link to the attachment.
Any help would be greatly appreciated.
The property you need to use is SPListItem.Attachments (documentation)
Since you haven't provided any code to work from I've had to make a simple example. I would suggest posting the code you're working on in future, you will receive much better replies.
using (var objSite = new SPSite("http://sharepointsite"))
{
using (var web = objSite.OpenWeb())
{
var objlist = web.Lists["Testing List"];
var objItem = objlist.GetItemById(1);
var attachments = objItem.Attachments;
}
}

Create SharePoint variation labels using CSOM

Can anyone tell me how to create SharePoint 2013 variation labels using client-side object model (CSOM). I know it is possible using SSOM and Powershell.
How to create Variation Labels in SharePoint 2013/Online via CSOM
VariationsClient class is intended for managing Variation Labels in SharePoint 2013.
The following operations are currently supported:
VariationsClient.CreateLabel method is used for create Variation Label
VariationsClient.GetLabelsList method gets Variation Labels on site
Usage
var variationsClient = new VariationsClient(ctx);
var siteLanguages = new[] {"en-US","ru-RU","fi-FI","nl-NL"};
foreach (var language in siteLanguages)
{
var isSource = (language == "en-US");
variationsClient.CreateLabel(new CultureInfo(language), isSource);
}
Result

Sharepoint 2010 - make Title, Description and Keyword fields as required fields in Picture Library using server-object-model

I'm creating a Sharepoint feature, this feature has an event receiver associated to it. In the event receiver, I'm creating a Document Library and Picture Library using server-side object model. I'm also adding new custom columns (around 80) to these newly created document and picture library. Now I want to modify the properties of the Description, Keywords and Title fields that are by default created along with the picture library. I want to make these fields as Required fields. How do I do this? I tried to set SPList.AllowContentTypes = true and try to change the attributes of these fields, but it doesn't work (neither gives an error nor makes these required fields). I also tried to access the content types and try to change the attributes using SPContentType.FieldsLinks["Column_name"].Required and SPContentType.Fields["Column_name"].Required but it gives me an error. Does anyone have any other suggestions?
Here is the answer....
SPContentType ct = mypiclib.ContentTypes["Picture"];
SPFieldLinks titleLink = ct.FieldLinks["Title"];
SPFieldLinks descLink = ct.FieldLinks["comments"]; //internal name of Description
SPFieldLinks keywords = ct.FieldLinks["keywords"];
titlelink.Required = true;
descLink.Required = true;
keywords.Required = true;
ct.Update();
can you tell us the error you got when trying to use the fieldlinks? Because this should work... I have done it like this:
SPContentType ct = web.Lists["*ListName*"].ContentTypes["*ContentTypeName*"];
SPFieldLinkCollection flinks = ct.FieldLinks;
flinks["*ColumnName*"].Required = true;
ct.update();
This should do the trick:
SPWeb yourWeb = ... //assign your web
SPList yourPictureLibrary = ... //assign your picture library
web.AllowUnsafeUpdates = true;
yourPictureLibrary.Fields[SPBuiltInFieldId.Title].Required = true;
yourPictureLibrary.Fields[SPBuiltInFieldId.Description].Required = true;
yourPictureLibrary.Fields[SPBuiltInFieldId.Keywords].Required = true;
yourPictureLibrary.Update();
SPAllowContentTypes isn't settable. You might try setting ContentTypesEnabled instead.
I don't have a 2010 box to test against, but if SPAllowContentTypes returns false I think you're looking at modifying the definition of your picture library in the 14 hive (TEMPLATE\FEATURES\PictureLibrary\PicLib) to get what you're after. Tread lightly there.

Resources