create link for document in Document Library using Client Object Model
-
31 iulie 2012 16:37
Hello All,
I have a document placed in a different location. ('http://ishare.xxxx.com/Doc1.docx') While creating folders, I need to generate a link to the location using client object model with in the document library where i m creating the folders.
Please help, I saw very few article regarding the same till now with no concrete answers.
Thanks in advance
Regards
Kajal
Toate mesajele
-
31 iulie 2012 17:22
If you have defined a link field for the folder contenttype then you can add a link to that field using the FieldUrlValue class in CSOM.
FieldUrlValue link = new FieldUrlValue(); link.Url = "http://microsoft.com"; link.Description = "Microsoft Technologies"; lstItem["DocLink"] = link; lstItem.Update(); clientContext.ExecuteQuery();Blog | SharePoint Field Notes Dev Tool | ClassMaster
-
31 iulie 2012 18:01
hello Steve,
Correct me if I'm wrong, to create link thru COM, first I have to define a link field for the document library inside which im trying to create the link?
So the snippet you have send, DocLink is the link field which needs to be created? please help with some e.g
Regards
kajal
-
2 august 2012 02:19
Here is some sample code to add a URL field to a list using CSOM.
public static void AddLinkField() { ClientContext context = new ClientContext("http://basesmc2008"); Web site = context.Web; string linkSchema = @"<Field Type='URL' DisplayName='DocLink' Required='FALSE' EnforceUniqueValues='FALSE' Indexed='FALSE' Format='Hyperlink' ID='{b3126091-bbc7-4ee1-b4ff-05f520cad1d8}' SourceID='{354fc616-433b-4a49-a44a-990e299d6b11}' StaticName='DocLink' Name='DocLink' /> "; ClientContext clientContext = new ClientContext("http://basesmc2008"); List list = clientContext.Web.Lists.GetByTitle("tester"); FieldCollection fields = list.Fields; clientContext.Load(list); clientContext.Load(fields); clientContext.ExecuteQuery(); Field linkField = fields.AddFieldAsXml(linkSchema, true, AddFieldOptions.AddToAllContentTypes); linkField.Update(); clientContext.Load(linkField); clientContext.ExecuteQuery(); }Blog | SharePoint Field Notes Dev Tool | ClassMaster
-
2 august 2012 04:22
Hi,
Please refer the below link
http://ranaictiu-technicalblog.blogspot.ca/2010/07/sharepoint-document-library-add.html
Regards,
-
2 august 2012 21:11
Hello Steve,
Thanks a lot for your inputs, I tried to put this snippet in a console application to run and check , first time it ran but I did not see any link, second time I tried running it,it says...
ID='{b3126091-bbc7-4ee1-b4ff-05f520cad1d8}' already exists...So I do not know how do I check where it created, and how do I generate this linkschema? may be very basic question but if you can help to clear this out I would be very grateful. My Code
var credentials = new NetworkCredential("Mishas50", "**********", "Enterprise");
ClientContext context = new ClientContext("http://daywinwebp003:17362/sites/DEVDOCLIB");
Web site = context.Web;
string linkSchema = @"<Field Type='URL' DisplayName='DocLink'
Required='FALSE' EnforceUniqueValues='FALSE'
Indexed='FALSE' Format='Hyperlink'
ID='{b3126091-bbc7-4ee1-b4ff-05f520cad1d8}'
SourceID='{354fc616-433b-4a49-a44a-990e299d6b11}'
StaticName='DocLink' Name='DocLink' /> ";
ClientContext clientContext = new ClientContext("http://daywinwebp003:17362/sites/DEVDOCLIB");
List list = clientContext.Web.Lists.GetByTitle("PortalDevDoc");
FieldCollection fields = list.Fields;
clientContext.Load(list);
clientContext.Load(fields);
clientContext.ExecuteQuery();
Field linkField = fields.AddFieldAsXml(linkSchema, true, AddFieldOptions.AddToAllContentTypes);
linkField.Update();
clientContext.Load(linkField);
clientContext.ExecuteQuery();Regards
Kajal
-
2 august 2012 21:12
Hello,
Can you put some light on CLient Object Model, the code you referred is for server object.
Regards
Kajal