I need to programmatically, using C#, add the SharePoint Web Part "Site Users" to a page.
I know how to add web parts but how do I get the "Site Users" web part from Share Point? I do not know how to instance it.
Thanks for helping.
The answer turned out to be the Members Web Part.
By simply setting "Display Type" to "WebUserGroups" the web part lists the groups and users on the site.
MembersWebPart membersWebPart = new MembersWebPart();
membersWebPart.DisplayType = MembersWebPartDisplayType.WebUserGroups;
membersWebPart.Title = "Användare och grupper";
wpManager.AddWebPart(membersWebPart, "Right", 2);
Related
I’m working with the .NET Microsoft Graph SDK, and I had a question about the best way to create a Sharepoint Site that is accessible by all members that are part of a tenant. I’m currently creating a Group and using the Group's root Site:
GraphServiceClient client = GetGraphClient();
Group group = await client.Groups.Request().AddAsync(new Microsoft.Graph.Group
{
DisplayName = "A display name",
Description = "Description",
MailEnabled = false,
MailNickname = "a_mail_nickname",
SecurityEnabled = false,
GroupTypes = new[]{"Unified"}
});
Site site = await client.Groups[groupId.ToString()].Sites["root"].Request().GetAsync();
//create file using site.Id as the target
Will taking this approach prevent other members of the Sharepoint tenant from being able to access the Site? Thank you for the help!
To programmatically access the group, below mentioned permission is needed.
As per the documentation, to access the team site for a group, below mentioned permission is needed.
it is been few days that I can not post a message from my app to specific groups of friends in Facebook, I am using asp.net MVC, before that I was using following code to post for only one list of friends " for example: close friend" but now it always post to all friends even when I specify target group.
FacebookClient fpost1 = new FacebookClient(context.AccessToken.ToString());
fpost1.Post("/me/feed", new { message = "test message", to = "xxxxxxxxxxxxxx" });
what should be changed to post for only specific list. consider xxxxxxxxxxxx as a close friend list id.
Assuming your app is a website, the easiest way to do this is to just use the share button and let the user pick the group he wants to post to.
https://developers.facebook.com/docs/plugins/share-button/
If your app is mobile, you can use the Share Dialog
https://developers.facebook.com/docs/ios/share
https://developers.facebook.com/docs/android/share
user can share a link from inside my app:
ShareLinkTask linkTask = new ShareLinkTask();
linkTask.Title = "I like it";
linkTask.Message = "I love this movie";
linkTask.LinkUri = new Uri(link, UriKind.Absolute);
linkTask.Show();
problem: I want to include my app's name too something like this sent by my awesome app!. If I append this to Message user can remove it. How can I add my app name without user be able to remove it? thanks.
This is not possible with the built in share tasks, probably to protect the user from an app posting text without permission. To get this functionality you will have to implement it by working directly with the Facebook, Twitter, etc. APIs.
I am wondering if there is a way to update all site home pages to display a new custom web part.
I have a site collection with 100+ sub sites and I have created a custom web part which i want to display in all site home pages.. what would you suggest as the best way to do this, as as doing this manually will take considerable time?!
First write the code to programmatically add a webpart to a single homepage. The specifics of how to do this will vary based on how your homepage is structured, whether it's a publishing page, etc. It's most likely possible, but implementations could differ. You'll possibly be using something similar to this:
using(SPSite site = new SPSite("http://localhost"))
using(SPWeb web = site.RootWeb)
{
web.AllowUnsafeUpdates = true;
SPLimitedWebPartManager webParts = web.GetLimitedWebPartManager("Pagees/Home.aspx"
, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
MyWebPart wp = new MyWebPart(); // your custom webpart
wp.Title = "My WebPart";
webParts.AddWebPart(wp, "Left", 0);
webParts.SaveChanges(wp);
}
There are lots of variations when searching the subject online.
Once you have that you can create either a console application or a feature to be executed on the top level site, open up each subsite, and then execute the above code.
I need to get the url of the site so that I render a user control on only the main page. I need to check for http://foo.com, http://www.foo.com, and foo.com. I am a bit stumped as to how check for all 3. I tried the following which does not work.
string domainName = Request.Url.Host.ToString();
if (domainName == "http://nomorecocktails.com" | Request.Url.Host.Contains("default.aspx"))
{ //code to push user control to page
Also tried
var url = HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + "/";
Any thoughts?
You need to check if the Request.Path property is equal to / or /Default.aspx or whatever your "main page" is. The domain name is completely irrelevant. What if I accessed your site via http://192.56.17.205/, and similarly, what if your server switched IP addresses? Your domain check would fail.
If you utilize the QueryString to display different content, you'll also need to check Request.QueryString.
Documentation for Request.Path:
http://msdn.microsoft.com/en-us/library/system.web.httprequest.path.aspx
Documentation for Request.QueryString:
http://msdn.microsoft.com/en-us/library/system.web.httprequest.querystring.aspx
If you need the user control to only appear on the main page (I'm assuming you mean home page), then add the code to call the user control to the code behind of that file.
If this code is stored in the master page, then you can reference it like:
Master.FindControl("UserControlID");
If you are only using the one web form (ie. just Default.aspx), then you can check that no relevant query strings are included in the URL, and display only if this is the case:
if (Request.QueryString["q"] == null){
//user control code
}
However if you are using this technique then I would recommend using multiple web forms using master pages in the future to structure your application better.
The ASP.NET website has some good tutorials on how to do this:
http://www.asp.net/web-forms/tutorials/master-pages