Print multiple documents in sharepoint client object model
Hi All,
I have a content editor webpart which displays documents from document library using sharepoint client object model.
test1 test2 test3 test4 are documents from document library.
I have requirement to print the selected documents in single click of print button.
once I clicks on print button all the selected documents should get printed.
Is there any way to achieve this....?
Regards
Srinivas
srinivas
Hi Srinivas,
You can do this but it will be combination of ECMA and JS. First you need to get selected file name by ECMA script then call a java script function to print documents.
Here is script to print all docs: http://stackoverflow.com/questions/7187400/printing-multiple-pdf-files-using-javascript
Hope it could help
Hemendra: "Yesterday is just a memory,Tomorrow we may never see"
Whenever you see a reply and if you think is helpful, click "Vote As Helpful"! And whenever
you see a reply being an answer to the question of the thread, click "Mark As Answer
Similar Messages
-
Rename a File in a SharePoint document library through Client object model
Hi,
How to Rename a File in a SharePoint document library through Client object model?
Thanks
Poomani SankaranHi,
According to your description, you want to rename file in the document library using SharePoint Client Object Model.
Here is a code snippet works well in my environment for your reference:
static void Main(string[] args)
string url = "http://sp2013sps/sites/test/";
ClientContext clientContext = new ClientContext(url);
Microsoft.SharePoint.Client.List spList = clientContext.Web.Lists.GetByTitle("Documents");
clientContext.Load(spList);
clientContext.ExecuteQuery();
if (spList != null && spList.ItemCount > 0)
Microsoft.SharePoint.Client.CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml =@"<View> <Query> <Where><Eq><FieldRef Name='LinkFilenameNoMenu' /><Value Type='Computed'>New Microsoft Word Document.docx </Value></Eq></Where> </Query> <ViewFields><FieldRef Name='Title' /></ViewFields> </View>";
ListItemCollection listItems = spList.GetItems(camlQuery);
clientContext.Load(listItems);
clientContext.ExecuteQuery();
listItems[0]["Title"] = "word.docx";
listItems[0]["FileLeafRef"] = "word.docx";
listItems[0].Update();
clientContext.ExecuteQuery();
More information about SharePoint Client Object Model:
http://msdn.microsoft.com/en-us/library/office/ee537247(v=office.14).aspx
http://www.codeproject.com/Articles/399156/SharePoint-Client-Object-Model-Introduction
http://www.learningsharepoint.com/2010/07/12/programmatically-upload-document-using-client-object-model-sharepoint-2010/
Best regards -
How to get all previous versions page contents and other field values of a publishing page using SharePoint Client Object Model 2010?
Thanks,
OsmitaHi Osmita,
Greetings.
Here are the links that helps you. It has code attached to it.
http://social.technet.microsoft.com/Forums/sharepoint/en-US/a0d2ab40-99ba-4368-8505-1dc559ef6469/get-content-of-previous-version-of-page-sharepoint-2010?forum=sharepointgeneralprevious
http://social.technet.microsoft.com/Forums/sharepoint/en-US/faaf419f-997e-4150-9911-48cc375c3b46/how-to-get-previous-published-versions-of-publishing-pages-in-sharepoint-2010?forum=sharepointdevelopmentprevious
Please remember to click 'Mark as Answer' on the answer if it helps you -
Using Sharepoint Client Object Model with large libraries (more than 5000 elements)
Hi,
i have issue with acccessing large list with more than 5000 elements. I use a Sharepoint Client Object Model.
It worked till yesterday when in the list was less than 5000. Now there is in the library more than 5000 elements. I have changed in the Central Administration limit for list from 5000 to 10000, but it helped only for list views. Script returns now 0 records.
var clientContext = new SP.ClientContext.get_current();
var currentListId =_spPageContextInfo.pageListId;
oList = clientContext.get_web().get_lists().getById(currentListId);
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml('<View Scope=\"RecursiveAll\">'+
'<Query>'+
'<Where>'+
'<And>'+
'<Eq><FieldRef Name=\"ContentTypeId\"/><Value Type=\"Text\">'+contentTypeId+'</Value></Eq>'+
'<And>'+
'<Eq><FieldRef Name=\"_x0040_Client\" LookupId=\"TRUE\" /><Value Type=\"Lookup\">'+client+'</Value></Eq>'+
'<Eq><FieldRef Name=\"_x0040_Company\" LookupId=\"TRUE\" /><Value Type=\"Lookup\">'+organisation+'</Value></Eq>'+
'</And>'+
'</And>'+
'</Where>'+
'</Query>'+
'<ViewFields>'+
'<FieldRef Name=\"ID\" />'+
'</ViewFields>'+
'</View>'+
'<RowLimit>100</RowLimit>');
camlQuery.ViewAttributes = "Scope='RecursiveAll'";
listItems = oList.getItems(camlQuery);
clientContext.load(listItems);
clientContext.executeQueryAsync(Function.createDelegate(this, onQuerySucceeded), Function.createDelegate(this, onQueryFailed));
Please advice how i can resolve this issue. Thanks a lot!!
from MSDN forum...Thanks you, friends!
That to resolve my issue, i made next things:
1) turn off a limit items for my list
2) used SPQuery.ListItemCollectionPosition
property,
3) and corrected little mistake in my CAML Query.
May be a punkt #2 will be enough, don't you :)
from MSDN forum... -
Through SharePoint Client Object model, how to make color coded events on Sharepoint Calendar
Hi,
Through SharePoint Client Object model, how to make color coded events on Sharepoint Calendar.
Plese share your knowledge.
Regards
TharakHi,
According to your post, my understanding is that you wanted to make a color events Calendar.
We can achieve it using the OOB method by creating the Calendars Overlay.
http://summit7systems.com/color-code-calendar-events-in-sharepoint/
You can also use the JavaScript to achieve it.
http://spsawyer.wordpress.com/2013/07/18/sharepoint-color-calendar/
http://www.planetwilson.co.uk/sharepoint-2013-colour-calendar-v2/
more reference:
http://usermanagedsolutions.com/SharePoint-User-Toolkit/Pages/Color-Coding-Calendar-List.aspx
http://blog.pathtosharepoint.com/2010/04/06/tutorial-add-color-coding-to-your-sharepoint-2007-calendar-in-15-minutes/#comment-7231
Thanks & Regards,
Jason
Jason Guo
TechNet Community Support -
Sharepoint client object model - Pull files from one site and move to another
Dear All,
I am using client object model to retrieve files of certain criteria using caml query and copy them to some other site using
client object model. There is no exception being thrown, but the application is not performing either. No files are being copied to destination. Here is the code. Please advise.
The message box that I have kept at the end is being displayed, but no files are being copied.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Net;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.SharePoint;
using SP = Microsoft.SharePoint.Client;
namespace WindowsFormsApplication2
public partial class Form1 : Form
public Form1()
InitializeComponent();
private void Form1_Load(object sender, EventArgs e)
private void button1_Click(object sender, EventArgs e)
SP.ClientContext srcContext = new SP.ClientContext(textBox1.Text);
srcContext.Credentials = new NetworkCredential(textBox3.Text, textBox4.Text, textBox5.Text);
SP.ClientContext destContext = new SP.ClientContext(textBox2.Text);
destContext.Credentials = new NetworkCredential(textBox3.Text, textBox4.Text, textBox5.Text);
SP.CamlQuery camlQuery = new SP.CamlQuery();
camlQuery.ViewXml = "<View Scope='RecursiveAll'><Query><Where><And><Geq><FieldRef Name='Created' /><Value IncludeTimeValue='TRUE' Type='DateTime'>2013-01-01T04:16:20Z</Value></Geq><And><Lt><FieldRef
Name='Created' /><Value IncludeTimeValue='TRUE' Type='DateTime'>2013-12-31T04:16:43Z</Value></Lt><Or><Eq><FieldRef Name='Document_x0020_Classification' /><Value Type='Choice'></Value></Eq><Eq><FieldRef
Name='Document_x0020_Classification' /><Value Type='Choice'>Case Studies</Value></Eq></Or></And></And></Where></Query></View>";
SP.Web oWebsite = srcContext.Web;
srcContext.Load(oWebsite, website => website.Webs);
srcContext.ExecuteQuery();
SP.Web dWebsite = destContext.Web;
destContext.Load(dWebsite);
destContext.ExecuteQuery();
foreach (SP.Web web in oWebsite.Webs)
MessageBox.Show(web.Title);
foreach (SP.List list in web.Lists)
if (list.BaseType.ToString() == "DocumentLibrary")
MessageBox.Show(list.Title);
SP.ListItemCollection collListItem = list.GetItems(camlQuery);
srcContext.Load(collListItem);
srcContext.ExecuteQuery();
foreach (var doc in collListItem)
SP.File f = doc.File;
srcContext.Load(f);
srcContext.ExecuteQuery();
string destLibrary = "shared Documents";
string nLocation = dWebsite.ServerRelativeUrl.TrimEnd('/') + "/" + destLibrary.Replace(" ", "")
+ "/" + f.Name;
SP.FileInformation fileInfo = SP.File.OpenBinaryDirect(srcContext, f.ServerRelativeUrl);
SP.File.SaveBinaryDirect(destContext, nLocation, fileInfo.Stream, true);
MessageBox.Show("Completed");
sk.RakhishmaHi,
To copy files from one site collection to another site collection, the simplest way is to open document library in windows explorer view.
Go to document library, click library tab, click open with explorer.
You can open the document library1 in explorer then copy the files which you want to paste to another site collection
document library2, then open the document library2 in explorer to paste the documents.
Besides, there are other method:
https://social.msdn.microsoft.com/Forums/office/en-US/67282348-25c7-4bd0-9d95-61024c6892f9/how-we-move-a-document-library-from-one-site-collection-to-another-sitecollection?forum=sharepointgeneralprevious
https://social.msdn.microsoft.com/Forums/sharepoint/en-US/8c112d85-1ab8-426b-be37-d010cf8647fe/copy-a-list-from-one-site-collection-to-another-using-web-service
Best Regards,
Lisa Chen
TechNet Community Support
Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
[email protected] -
Add multiple people using Javascript Client Object Model
I am trying to add multiple people to a SP column of type Person/Group i.e. people picker. I am able
to add one successfully using their userId, but HAVE no clue how to do that for multiple people. Here is the code for one user:
function UserDrop(e, toElement, listGuid, columnName) {
//EcmaScript Client Object Model
var ctx = new SP.ClientContext.get_current();
var list = ctx.get_web().get_lists().getById(listGuid);
var item = list.getItemById(elementId);
//columnName is of type person/group and I am adding user //whose userId is 7
item.set_item(columnName, 7);
item.update();
// asynchronous call
ctx.executeQueryAsync(
function () { toElement.innerHTML = userLinkHtml; },
function () {alert ("Error")}
return false;
This works great and I can add user whose userId is 7, however I want to add multiple people like let's say users of user Ids 7 and 8.
Any ideas or help will be greatly appreciated.
There is a thread on this one but that's from .net COM which could accessed here: http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010general/thread/5183e87c-ee1d-4594-9492-0dfdf6616cce
7929Hi ,
Can somebody let me know how the same(assigning the array values to lookup value field) can be achieved with multi-select lookup value. SP.FieldLookUpValue do not have any such methods like fromUser. Please help. Please find my code block below
clientContext = new SP.ClientContext.get_current();
if (this.clientContext != undefined && clientContext != null) {
var webSite = clientContext.get_web();
oList = webSite.get_lists().getByTitle("Add New User");
$.urlParam = function(name){
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
return results[1] || 0;
var itemid = parseInt($.urlParam('ID'));
var item = oList.getItemById(itemid);
var users = new Array();
users.push(SP.FieldLookupValue.set_lookupId(1));
users.push(SP.FieldLookupValue.set_lookupId(2));
item.set_item('Responsibility', users);
item.update();
clientContext.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
also i cant use managed client object model.. so pls let me know how to achieve the same using javascript client object model
Ranjani.R -
Hi,
I have started using the client object model so that i do not have to go to sharepoint admins to perform some basic operations on remote server. While assigning list item level permission i am getting following error, could you please help. thanks.
The remote server returned an error: (401) Unauthorized.
at
System.Net.HttpWebRequest.GetResponse()
at
Microsoft.SharePoint.Client.SPWebRequestExecutor.Execute()
at
Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest()
at
Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
at
SetDowntimeItemPermission.SetPermission.Main(String[] args) init seems your request was unauthenticated i'm not sure are you using a web application with FBA or desktop application my suggestion would be try to impersonate your request by passing network credentials (COM works on network credentials )
NetworkCredential credentials = new NetworkCredential("username", "pwd", "domain");
ClientContext context = new ClientContext("http://site-url");
context.Credentials = credentials;
Best Regards, Ashutosh | SharePoint World -
How to register a new docicon/progid using CSOM/SharePoint Client object model
I know how to register a new file-type icon in SharePoint 2013 by modifying docicon.xml,
but is it possible via any sort of web-based API? Specifically I'm trying to do it for a SharePoint Online/office 365 site.Hi Dylan,
For SharePoint Online, the docicon.xml is stored in the SharePoint online Server and there is no such Web API could modify the xml file directly, so there is no easy way to achieve it.
As a workaround, you can add some JavaScript and Jquery in the master page to modify the file type icon to the new one.
<script>
var IMGs = document.getElementsByTagName("IMG")
for (var i=0; i<IMGs.length; i++)
var alt=IMGs[i].alt;
if (alt.substring(alt.length-4,alt.length)==".pdf")
IMGs[i].src="/yourlibrary/yourimage.gif";
</script>
Here is a similar thread for your reference:
https://social.technet.microsoft.com/forums/msonline/en-US/bf5ff648-eefb-4084-8204-9519efaf50e7/modifying-dociconxml-on-sharepoint-online
Best Regards
Forum Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
[email protected]
Zhengyu Guo
TechNet Community Support -
I have a small snippet of code that I use to update the Modified Date of a list item and it works great for users with Full Control permissions. However, for users with just Contribute access to the site the code doesn't work. Instead, SharePoint
just updates the Modified Date to now.
I did some testing, and narrowed down the specific permission level that allows updating of Modified dates and oddly enough, it's the "Manage Permissions" level.
Has anyone run into this issue? If so, how do I work around this and update the Modified date as a user with only Contribute access to a site/library?
Here's the code:
DateTime Test = new DateTime(2012, 5, 4);
ListItem li = list.GetItemById(itemID);
li["Modified"] = Test;
li.Update();
ct.ExecuteQuery();
Thanks,
MaxHello,
As a workaround you can pass admin credential in your code because as per my knowledge contributor can't update default columns like: created by, modified by, modified, created.
ClientContext clientContext = newClientContext(siteUrl);
ClientContext.Credentials = newNetworkCredential(UserName, Password, Domain);
Hope it could help
Hemendra:Yesterday is just a memory,Tomorrow we may never see
Please remember to mark the replies as answers if they help and unmark them if they provide no help -
How to delete a custom columns from a content-type in Sharepoint Client object model
I have a windows interface where I create a content-type and then create a column and adds that column to the content-type.
//availableCT is my content-type where the column is present.
//get all available fields within this content-type
FieldCollection fieldColl = availableCT.Fields;
clientContext.Load(fieldColl);
clientContext.ExecuteQuery();
foreach (Field field in fieldColl)
//columnFromList is the column that is to be deleted
if (field.InternalName.Equals(columnFromList))
field.DeleteObject();
clientContext.ExecuteQuery(); // this throws an exception
// Additional information: Site columns which are included in content types or on lists cannot be deleted. Please remove all instances of this site column prior to deleting it.hi,
you can use the below code to delete it
using (ClientContext sourceContext = new ClientContext(cmdSpoSite))
Web web = sourceContext.Web;
sourceContext.Load(web);
sourceContext.Load(web.AvailableContentTypes, type => type.Include(c => c.FieldLinks, c => c.Name));
sourceContext.ExecuteQuery();
List<ContentType> ExistingContentType = web.AvailableContentTypes.ToList();
IEnumerable<ContentType> contentTypesList = ExistingContentType.Where(ct => ct.Name == "<ContentTypeName>");
ContentType ctype = contentTypesList.ElementAt(0);
IQueryable<FieldLink> flinks = ctype.FieldLinks.Where(f => f.Name == "<FiledName");
foreach (FieldLink flink in flinks)
flink.DeleteObject();
ctype.Update(true);
sourceContext.ExecuteQuery();
The difference being in your code and above code is you are removeing fileds which is eventually is deleting site column but a site column cannot be deleted if is alreday being used. So you need to deled the FieldLink in content type taht way column is removed
from content type but not from site column.
Now if you want to delete site column you can use your code to deleted Field.
Whenever you see a reply and if you think is helpful,Vote As Helpful! And whenever you see a reply being an answer to the question of the thread, click Mark As Answer -
How to execute XML batch commands using SharePoint Web services or Client Object Model
Hi,
I have a requirement to execute some batch commands to update SharePoint View Style, how can i do it using SharePoint webservices or SharePoint Client Object model.
I need to execute the following Batch command over a particular web.
<Method ID="UpdateView">
<SetVar Name="Cmd">UpdateView</SetVar>
<SetList Scope="Request">{GUID of List}</SetList>
<SetVar Name="View">{GUID of View}</SetVar>
<SetVar Name="ViewStyle">6</SetVar>
<SetVar Name="RowLimit">100</SetVar>
<SetVar Name="Paged">TRUE</SetVar>
</Method>Hi
I tried it already... But UpdateView Method in the Views.asmx and Lists.asmx, both are not supporting for updating the style of the view (like Boxed, Newsletter...).
If you have any code sample which will do this job with any of the SharePoint web services, please share it.. -
Trying to use Web LCID property to get the List name in client object Model
Hi ,
I am trying to change the "Personal Documents" list NoCrawl property under MySite using SharePoint Client Object Model. As we use web.Lists.GetByTitle("Personal
Documents"); method to get the list,but here problem is :for different language List name is in their language.So I tried to use LCID property of the WEB and
have taken key-value pair (PersonalSiteOnet_List_PersonalDocuments) from the resource file for that language from 14 hive.
Example:I have selected Spanish language .there are so many LCID for Spanish language but Microsoft has given only one language pack for Spanish.
Then,My Question is that
"All LCID for Spanish language are using same Spanish language pack dictionary file OR something else"
Hi,
According to your post, my understanding is that your requirement is getting list in different language.
Here are two ways for your reference:
1. We can use getById method instead, so that we can avoid the language issue.
2. We can use an array to store the different list name in different language in you JavaScript code, then use the code snippet below to get the list:
var userLcid =_spPageContextInfo.currentLanguage;
var localizedStrings = {
ListName: {
_1033: "EnglishName",
_3082: "SpanishName"
var listName=localizedStrings.ListName["_" + userLcid];
var list=web.Lists.getByTitle(listName);
More information:
http://msdn.microsoft.com/en-us/library/hh670609.aspx
http://wellytonian.com/2012/11/language-packs-sharepoint-2010/
Best Regards
Dennis Guo
TechNet Community Support -
The below mentioned code works sometimes and doesn't most of the time. What is the real best way to update multi select managed metadata fields?
Microsoft.SharePoint.Client.File file = site.GetFileByServerRelativeUrl("/sites/myspsite/Documents/Presentation2.pptx");
clientContext.Load(file);
clientContext.ExecuteQuery();
ListItem currentItem = file.ListItemAllFields;
clientContext.Load(currentItem);
clientContext.ExecuteQuery();
currentItem["Country"] = "-1;#India|1d13cfe9-d6f4-4bd3-a6c7-4b46a81f2a96;#-1;#China|9c1dff73-82db-44b1-8d70-f4258dd24e47;#-1;#USA|b9295c0b-67d4-4dc5-99d4-e88af888de48";
currentItem["Title"] = "Demo Doc";
currentItem.Update();
clientContext.ExecuteQuery();
file.CheckIn("test check-in", CheckinType.MajorCheckIn);
clientContext.ExecuteQuery();
Anuradha!!Hi,
Here are two blog for your reference:
How to Work with Managed Metadata Columns by Using the SharePoint Client Object Model
http://blogs.msdn.com/b/sharepointdev/archive/2011/11/18/how-to-work-with-managed-metadata-columns-by-using-the-sharepoint-client-object-model-kaushalendra-kumar.aspx
SharePoint 2010 Code Tips – Setting a Managed Metadata Field with the Client Object Model
http://sharepointfieldnotes.blogspot.com/2011/08/sharepoint-2010-code-tips-setting.html
Best Regards
Dennis Guo
TechNet Community Support -
I'm using the SharePoint 2013 Client Object Model to access a site that is either in Office 365 or behind an ADFS 3.0 login screen, is it sufficient to use the new SharePointOnlineCredentials credentials
or do I need other types of credentials for the sites behind ADFS 3.0 ? Is so, what type of credentials would I use for the sites behind ADFS 3.0?
using (ClientContext ctx = new ClientContext(siteUrl))
ctx.Credentials = new SharePointOnlineCredentials("some user", "a secure string password");
while (ctx.HasPendingRequest)
ctx.ExecuteQuery();
// etc.Hi,
According to your post, my understanding is that you want to know the ways to get credential either in Office 365 or sites behind ADFS 3.0.
For Office 365, you can use SharePointOnlineCredentials Object to get credential. For SharePoint sites behind ADFS 3.0, you can use NetworkCredential Object:
ctx.Credentials = new NetworkCredential(UserName, Password, Domain);
The link below will provide more information about using the ADFS FedAuth Token programmatically through the SharePoint Client Object Model:
http://samirvaidya.blogspot.com/2013/05/using-adfs-fedauth-token.html
Best regards
Patrick Liang
TechNet Community Support
Maybe you are looking for
-
Why is it taking so long to download iCloud onto new phone
Why is it taking so long to download my iCloud onto new phone
-
Problem in creating Receiver Agreement using Integration Directory API
Hello Experts, We are developing a scenario where we are creating "REceiver Agreement" through Integration Directory API. This requires certain parameters like Sender component, Interface, Communication Channel & Namespace to be set in the code.The r
-
Hi 1.Using the LSMW interface i want to upload my Purchase order data from the flat file . And i want to Capture the Error Records which is to be displayed in ALV format , Success Records in SAP Script. Provide me the sample code or links which will
-
Urgent:Regarding the Pre-Installation Tasks
Hi, I have a scenario: Currently, i have installed Oracle AS Infrastructure(D'base 10.1.0.5.0) as a pre-requisite for installing oracle Content DB. My Question is : Is that mandatory that i have to again install oracle 10g database as pre-requisite b
-
CCMS Operating System Alert Monitor for Filesystem
Hi, In alert monitor set for operating system, for some filesystems the freespace & percentage_used were showing zero and saying value is obsolete. But those filesystem were existing with some space used in it. How to make that particular filesystem