How would I update the following CSOM search code to limit search scope to a single site in the SharePoint tenant:
KeywordQuery keywordQuery = new KeywordQuery(spClientContext);
keywordQuery.QueryText = term;
keywordQuery.StartRow = page;
keywordQuery.RowLimit = pageSize;
keywordQuery.EnableStemming = true;
keywordQuery.TrimDuplicates = false;
SearchExecutor searchExecutor = new SearchExecutor(spClientContext);
ClientResult<ResultTableCollection> resultTableCollection = searchExecutor.ExecuteQuery(keywordQuery);
spClientContext.ExecuteQuery();
Currently it brings back results from all sites. Using CSOM MS SP Client v4.0.30319. Thanks for the help!
You could add path managed property in QueryText to search in a specific site. For example:
keywordQuery.QueryText = "test path:https://tenant.sharepoint.com/sites/test";
Related
I am using this C# SDK to get data from Dynamics CRM 2011: https://msdn.microsoft.com/en-us/library/gg695803(v=crm.5).aspx
I need to read all the Accounts from it, the problem is, there are many accounts that are deactivated.
To get the accounts I am using the following code:
var accounts = xrm.AccountSet
.Select(acc => new
{
name = acc.Name,
guid = acc.AccountId,
parent = acc.ParentAccountId,
number = acc.AccountNumber,
website = acc.WebSiteURL,
});
This way has been suggested in this question: Retrieve list of all accounts in CRM through C#?
The problem is, this gets me all the accounts, both active and deactivated accounts. Is there any way to differentiate betweet those two?
Try something like:
var accounts = xrm.AccountSet.Where(acc => acc.StatusCode.Value == 0)
.Select(acc => new
{
name = acc.Name,
guid = acc.AccountId,
parent = acc.ParentAccountId,
number = acc.AccountNumber,
website = acc.WebSiteURL,
status = acc.StatusCode
});
For anyone wondering, I found the solution.
There is a StatusCode Field for each Account. Just extract it and check its value later.
var accounts = xrm.AccountSet
.Select(acc => new
{
name = acc.Name,
guid = acc.AccountId,
parent = acc.ParentAccountId,
number = acc.AccountNumber,
website = acc.WebSiteURL,
status = acc.StatusCode
});
Is there any other way?
I have just started using Sharepoint Foundation 2010 and I'm trying to write a function from c# to add pages to a site.
I got some code working to create a new site, but I can't seem to find any documentation about adding a page to an existing site using the client object model.
This is probably a simple question but if anyone can help me out I would appreciated it.
Thanks.
Update
This is what I have so far:
private void createPage()
{
ClientContext context = new ClientContext(url);
Site siteCollection = context.Site;
Web site = context.Web;
List pages = site.Lists.GetByTitle("Pages");
FileCreationInformation fileCreateInfo = new FileCreationInformation();
fileCreateInfo.Url = "NewPage";
fileCreateInfo.Content = System.Text.Encoding.ASCII.GetBytes("Test");
context.Load(pages.RootFolder.Files.Add(fileCreateInfo));
context.ExecuteQuery();
context.Dispose();
}
But I get a server exception "List 'Pages' does not exist at site with URL"
This is what I eventually did to add my page. Essentially I just needed to find the appropriate list title. These are just the names of the Document Libraries on the site.
private void createPage()
{
ClientContext context = new ClientContext(URL);
Site siteCollection = context.Site;
Web site = context.Web;
List pages = site.Lists.GetByTitle("Site Pages");
Microsoft.SharePoint.Client.
FileCreationInformation fileCreateInfo = new FileCreationInformation();
fileCreateInfo.Url = "NewPage.aspx";
context.Load(pages.RootFolder.Files.Add(fileCreateInfo));
context.ExecuteQuery();
context.Dispose();
}
If you are talking about creating a new site page I would recommend looking at this tutorial:
http://blogs.msdn.com/b/kaevans/archive/2010/06/28/creating-a-sharepoint-site-page-with-code-behind-using-visual-studio-2010.aspx
Take a second and make sure you actually want to add this through code. As someone who recently started development with SharePoint I can tell you that there is a fairly steep learning curve when working with the Object Model. Also, tasks that are easy to do through the UI may be quite difficult using code.
Good luck!!!
This Code works for me. It Creates an Page("NewPage.aspx") With the Content Test.
private void createPage()
{
ClientContext context = new ClientContext(URL);
Site siteCollection = context.Site;
Web site = context.Web;
List pages = site.Lists.GetByTitle("Site Pages");
Microsoft.SharePoint.Client.
FileCreationInformation fileCreateInfo = new FileCreationInformation();
fileCreateInfo.Url = "NewPage.aspx";
fileCreateInfo.Content = System.Text.Encoding.ASCII.GetBytes("Test");
context.Load(pages.RootFolder.Files.Add(fileCreateInfo));
context.ExecuteQuery();
context.Dispose();
}
I am using CRM 4.0 SDK to query kbarticles by keyword entered from a textbox on an asp.net webpage. I am using the SearchByKeywordsKbArticleRequest message to do this. Single keywords work fine, but if more than one word is entered a server error occurs. Here is my code:
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = "omitted";
CrmService service = new CrmService();
service.Url = "omitted"
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
//RetrieveMultipleResponse allArticlesResponse = getAllArticles();
SearchByKeywordsKbArticleRequest kb = new SearchByKeywordsKbArticleRequest();
String rawSearchText = keyword;
ColumnSet col = new ColumnSet();
col.Attributes = new string[] { "title", "kbarticleid" };
kb.ColumnSet = col;
kb.SearchText = rawSearchText.Trim();
kb.ReturnDynamicEntities = false;
SearchByKeywordsKbArticleResponse response =
(SearchByKeywordsKbArticleResponse)service.Execute(kb);
return response.BusinessEntityCollection;
Any clues?
That method uses the SQL Full-Text indexing service, so you would need to have full-text indexing setup in your database. You should be able to get more information about what's going wrong by enabling tracing in CRM. See:
http://social.microsoft.com/forums/en-us/crmdevelopment/thread/6A4CE7A3-29F3-4E5A-9A89-8E35D6FD05B9
The question basically says it all. I want to be able to get a list of all the users on the windows domain (i.e. in the active directory) using c#.
Thanks!
var dirEntry = new DirectoryEntry(string.Format("LDAP://{0}/{1}", "x.y.com", "DC=x,DC=y,DC=com"));
var searcher = new DirectorySearcher(dirEntry)
{
Filter = "(&(&(objectClass=user)(objectClass=person)))"
};
var resultCollection = searcher.FindAll();
SEE: Get all users from AD domain
I use google docs API(.net, c#) to share my document for other google user (ex: abc#gmail.com). Here's my code:
AclEntry entry = new AclEntry();
entry.Scope = new AclScope();
entry.Scope.Type = AclScope.SCOPE_USER;
entry.Scope.Value = "abc#gmail.com";
entry.Role = new AclRole();
entry.Role = AclRole.ACL_CALENDAR_READ;
Service service = createService(szUserName, szPassword);
string szAclUrl = ((DocumentEntry)contentEntry).AccessControlList;
Uri AclUri = new Uri(szAclUrl);
AtomEntry newAcl = service.Insert(AclUri, entry);
Note: service and contentEntry was created successfully.
But i get an error: (400) Bad Request when execute service.Insert(AclUri, entry) function.
What's i doing wrong? How can i add a new permission using google docs API(.net, c#)?
I think edit
entry.Role = new AclRole();
entry.Role = AclRole.ACL_CALENDAR_READ;
to :
entry.Role = new AclRole("reader"); or entry.Role = new AclRole("writer");