I'm useing 'Linq to SharePoint' and when I get a SharePoint context the list is empty (user haven't permission to this list).
using (SystemOcenContextDataContext ctx = new SystemOcenContextDataContext("url"))
{
// my code
}
I have tried something like this:
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SystemOcenContextDataContext ctx = new SystemOcenContextDataContext("url"))
{
// my code
}
});
but the context lists are still empty :( Any ideas?
this is another bug :) I find solution:
http://blogs.msdn.com/b/sowmyancs/archive/2010/09/19/linq-to-sharepoint-and-runwithelevatedprivileges.aspx
Related
I'm trying to make a targetingIdeaService API call to Google AdWords. This is my code so far:
[HttpGet]
public IEnumerable<string> Get()
{
var user = new AdWordsUser();
using (TargetingIdeaService targetingIdeaService = (TargetingIdeaService)user.GetService(AdWordsService.v201802.TargetingIdeaService))
{
// Create selector.
TargetingIdeaSelector selector = new TargetingIdeaSelector();
selector.requestType = RequestType.IDEAS;
selector.ideaType = IdeaType.KEYWORD;
selector.requestedAttributeTypes = new AttributeType[] {
AttributeType.KEYWORD_TEXT,
AttributeType.SEARCH_VOLUME,
AttributeType.AVERAGE_CPC,
AttributeType.COMPETITION,
AttributeType.CATEGORY_PRODUCTS_AND_SERVICES
};
// Set selector paging (required for targeting idea service).
var paging = Paging.Default;
// Create related to query search parameter.
var relatedToQuerySearchParameter =
new RelatedToQuerySearchParameter
{ queries = new String[] { "bakery", "pastries", "birthday cake" } };
var searchParameters = new List<SearchParameter> { relatedToQuerySearchParameter };
var page = new TargetingIdeaPage();
page = targetingIdeaService.get(selector);
return new string[] { "value1", "value2" };
}
}
it looks ok, compiles at last, and so on. But then I went into debug mode. And I saw this:
So as you can see, the variable doesn't have the access token. The other data comes from app.config file.
I am quite certain the keys passed in are correct.
Then the code throws the famous invalid_grand error. In my case, I believe that's because the access token is not being generated. I'm new to AdWords and ASP.NET, so I probably missed something, but I have no idea what.
I used the
docs,
Code Structure instructions, and
code examples to put it all together.
I had my configuration wrong. I had to recreate all the credentials using incognito window. If you have any issues just open a thread here: https://groups.google.com/forum/#!forum/adwords-api
I am getting error while retrieving users under the group from active directory. Error description is
{"Information about the domain could not be retrieved (1355)"}. Tried with .Net 4.0 and .Net 4.5.
The line for which I am getting the error is commented with the error message.
public List<DirectoryUser> GetUsersUnderGroup(string groupName)
{
var directoryUserList = new List<DirectoryUser>();
string directoryServerIp="192.168.1.xxx";
string ouName="xxxOuName";
string domainComponents="DC=xxxComopnent1,DC=xxxComponent2";
string directoryAdminUserId="directoryAdminuser";
string directoryAdminPassword="directoryAdminPassword";
using (var principalContext = principalContext = new PrincipalContext(ContextType.Domain, directoryServerIp, string.Format("OU={0},{1}", ouName, domainComponents), directoryAdminUserId, directoryAdminPassword);)
{
using (var group = GroupPrincipal.FindByIdentity(principalContext, groupName))
{
if (group != null)
{
var users = group.GetMembers(true);
//Works fine till the above line. variable users is having not null value but
//exception while iterating through the loop.Following is the exception
//{"Information about the domain could not be retrieved (1355)."}
foreach(var user in users)
{
Console.Write(user.DistinguishedName);
}
}
}
}
return directoryUserList;
}
Code for creating PrincipalContext is working fine in other scenarios (like fetching list of groups and OU's etc )
This article describes reasons for your issue and possible solutions: link. Basically, you have to use DirectoryEntry class if you run your code not from machine, where domain controller lies.
This article should help you to understand that class: link
I am trying to use the TFS API to scan through all my bug workitems, and see if there are any with no associated test cases. I was thinking about using bug.Fields[26].Value == 0 to see how many Related Links there are, but I am not sure if test cases are the only things that are considered related links.
If there are no test cases associated with the bug, I want to create a test case for it. I already know how to create a test case in general, but not one that is associated with an existing bug.
Can someone tell me how to do these things? Thanks.
Any work item that is linked to your Bug is considered a RelatedLink. Check here for the available types that derive from Link and also this SO-post by #bryanmac.With the following you should be able to retrieve the type of each related work item of your bug 123456.
using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
namespace WorkItemLinksOfAWorkItem
{
class Program
{
static void Main()
{
TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://TFSURI"));
var workItemStore = (WorkItemStore)teamProjectCollection.GetService(typeof(WorkItemStore));
var workItem = workItemStore.GetWorkItem(123456);
LinkCollection links = workItem.Links;
foreach (Link link in links)
{
if (!(link is RelatedLink))
continue;
var relLink = link as RelatedLink;
var relatedWI = workItemStore.GetWorkItem(relLink.RelatedWorkItemId);
Console.WriteLine(relatedWI.Id+" "+relatedWI.Type.Name);
}
}
}
}
(I had originally found the base of these sources in Scrum Dashboard)
In order to generate a new Test Case for your Bug 123456 you could try something like:
var workItemTypes = workItemStore.Projects["TeamProjectName"].WorkItemTypes;
var workItem = new WorkItem(workItemTypes["Test Case"]) {Title = "Programmatically constructed via TFS-SDK"};
var relatedLinkToBug = new RelatedLink(123456);
var links = workItem.Links;
links.Add(relatedLinkToBug);
workItem.Save();
I've been trying to get all the RoleAssignments using the COM interface. the problem is that i get the AD user group names instead of the actual users inside the groups.
my code looks something like this:
ClientContext cc = new ClientContext(#SiteURL);
RoleAssignmentCollection Roles = cc.Web.RoleAssignments;
IEnumerable<RoleAssignment> newRoleAssignmentsCollection = cc.LoadQuery(Role.Include(role => role.Member));
AsyncDelegate execDel = new AsyncDelegate(cc.ExecuteQuery);
execDel.BeginInvoke(arg => { cc.ExecuteQuery();
foreach (RoleAssignment RoleAssign in newRoleAssignmentsCollection)
{
RoleAssign.Member.LoginName; // <------- Here is my problem!!!
}
}, null);
Can anyone please tell me how to get the users which are inside the Active Directory group?
Thanks in advance, Itay.
I created web part (something like wizard) and need change item value in list, but when get list item, they haven't items (logged user haven't access to this list). Can I ignore sharepoint permission, and update this value?
I use LINQ to sharepoint and get context:
using (SystemOcenContextDataContext ctx = new SystemOcenContextDataContext("http://sh2010/sites/270"))
{
// code :)
}
Update:
make test when get list using:
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite ElevatedSite = new SPSite("http://sh2010/sites/270"))
{
using (SPWeb ElevatedWeb = ElevatedSite.OpenWeb())
{
list = ElevatedWeb.Lists["Ankiety i oceny"];
}
}
});
the object list "have" items
but in my project I use sharepoint linq datacontext when using:
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SystemOcenContextDataContext ctx = new SystemOcenContextDataContext("http://sh2010/sites/270"))
{
item = ctx.AnkietyIOceny.First();
}
});
the context(ctx) didn't have any items :/
any idea?
SPSecurity.RunWithElevatedPrivileges(delegate()
{
// Pur your code here.
});
Get more details Here
The SharePoint linq provides doesn't work with ElevatedPrivileges. It accesses the SPWeb.Current instance which will have the access rights of the request and not the elevated user.
http://jcapka.blogspot.com/2010/05/making-linq-to-sharepoint-work-for.html
There's a work around, which I've implemented generally the same thing. It's a big awkward but it works as far as I can tell.