How to retrieve rendered Sharepoint WebPart Data using Client Object Model - c#

I am trying to access data remotely from sharepoint 2010 site using client object model. For some restrictions I am not able to use CAML query even if I use I am not able to filter for proper audiences based on user login (if you can help me regarding the CAML query is also fine :: i do not know how to get current user audience name and all audiences using CAML/client object model. This code sits on the mobile site and calling the share point site as shown in my code). This following code works good but not able to get the content from the webpart. Can someone help regarding this.
using (ClientContext ctx = new ClientContext("https://mysite.com/Pages/Default.aspx"))
{
ctx.ExecutingWebRequest += new EventHandler<WebRequestEventArgs> (clientContext_ExecutingWebRequest);
File home=ctx.Web.GetFileByServerRelativeUrl("/Student/Pages/default.aspx");
//get the web part manager
Microsoft.SharePoint.Client.WebParts.LimitedWebPartManager wpm = home.GetLimitedWebPartManager(Microsoft.SharePoint.Client.WebParts.PersonalizationScope.Shared);
IEnumerable<Microsoft.SharePoint.Client.WebParts.WebPartDefinition> wpds = null;
//create the LINQ query to get the web parts from
//the web part definition collection
wpds = ctx.LoadQuery(wpm.WebParts.Include(wp => wp.Id,wp => wp.WebPart));
//load the list of web parts
ctx.ExecuteQuery();
//enumerate the results
foreach (Microsoft.SharePoint.Client.WebParts.WebPartDefinition wpd in wpds)
{
string title= wpd.WebPart.Title;
Microsoft.SharePoint.Client.WebParts.WebPart wpart = wpd.WebPart;
????? How to render and receive the data (looking for the same data When you browse the site with the browser)
}
Code continues...

I am also struggling with this issue. It really looks like this is not possible with client object model. Actually i've asked it to some SharePoint staff member at Build Conference 2012.
But, with the SharePoint Designer it's actually possible to download the wanted WebPart. Fiddler may come handy to track down which service will deliver you the bits.
Take a look at this post here on SharePoint StackExchange
Unfortunately the post will not give you any concrete way to solve it.
Wish you good luck!

Related

Simplified LDAP/AD Server on C#

I've searched without much success to the simplest (and yet working) example of an LDAP/AD Server for C#. Many libraries exist to connect to LDAP servers, but not the LDAP Server by itself (on C#).
I found however some information about it and even a post requesting a simple LDAP server that was answered "LDAP isn't simple"; and yet i read a lot of the RFC4511 and this sample code at GitHub Flexinet LDAP Server, but unfortunatly i don't have yet the knowledge to complete it's code.
My goal is not to make a fully functional LDAP server, but one that can at least do:
Serve as a login pool for softwares that allow it's users to be
registered and log on a AD/LDAP server (just check for login and
password for authentication).
Allow softwares like Outlook and Thunderbird to get a list of users (without passwords) with first and last name, e-mail address, phone number and department for contact list model.
No delete, add (or create), move, and other
functions are required since the main software that i aim to
integrate it with will do all the user and group management.
UPDATE
I'm trying to implement the Flexinet sample and adjust to that functionalities; as form of a question what should i do to change this function to prevent it from causing an exception (on the "var filter = searchRequest.ChildAttributes[6];" line it always breaks) when i call from a LDAP client software:
private void HandleSearchRequest(NetworkStream stream, LdapPacket requestPacket)
{
var searchRequest = requestPacket.ChildAttributes.SingleOrDefault(o => o.LdapOperation == LdapOperation.SearchRequest);
var filter = searchRequest.ChildAttributes[6];
if ((LdapFilterChoice)filter.ContextType == LdapFilterChoice.equalityMatch && filter.ChildAttributes[0].GetValue<String>() == "sAMAccountName" && filter.ChildAttributes[1].GetValue<String>() == "testuser") // equalityMatch
{
var responseEntryPacket = new LdapPacket(requestPacket.MessageId);
var searchResultEntry = new LdapAttribute(LdapOperation.SearchResultEntry);
searchResultEntry.ChildAttributes.Add(new LdapAttribute(UniversalDataType.OctetString, "cn=testuser,cn=Users,dc=dev,dc=company,dc=com"));
searchResultEntry.ChildAttributes.Add(new LdapAttribute(UniversalDataType.Sequence));
responseEntryPacket.ChildAttributes.Add(searchResultEntry);
var responsEntryBytes = responseEntryPacket.GetBytes();
stream.Write(responsEntryBytes, 0, responsEntryBytes.Length);
}
var responseDonePacket = new LdapPacket(requestPacket.MessageId);
responseDonePacket.ChildAttributes.Add(new LdapResultAttribute(LdapOperation.SearchResultDone, LdapResult.success));
var responseDoneBytes = responseDonePacket.GetBytes();
stream.Write(responseDoneBytes, 0, responseDoneBytes.Length);
}
The code is on the github link.
Finally i made a fork of the Flexinet LDAP Server on #Sammuel-Miranda/LdapServerLib and with the author's support and some changes and adaptations i completed this implementation. It responds to the bind and search calls and works perfectly for Outlook and Thunderbird to use as a shared address book.
I did not implemente however any ADD/MODIFY/DELETE request (but would not be hard to do) since i don't need then.
I found on the RFC4511 the explanation on how the search works ... and i'm "kind" of understanding it, not very well - and i see that the method implemented on the GitHub from Flexinet LDAP Server only answer to bind and search requests of one single user (since it's only a example implementation).
The client is requesting diferent calls to verify capabilities, structure and other info before making the search request itself. So i'll implement it all, one by one.
Still, if any other lib (in C#) exists, and anyone know about, would be better than writing a hole new server. If my implementation works, i'll fork it on github and share.

Deleting content based upon document type using the Umbraco content service

I've written a web service call that dynamically creates pages based upon the response from a web service every 60 seconds. The service I am using is a simple weather forecast service that gives a 7 day forecast of the weather in a specific region. All of the new content nodes are created using the following:
var weather = cs.CreateContent("Weather Forecast " + forecast.Date, rootID, "weather"); // Where rootID is the homepage of the site
As I'm ultimately going to adapt this web service call to only display one set of results (the most recent set) I wish to try and delete the content based upon the document type. Is this possible? From what I have seen here: http://our.umbraco.org/documentation/reference/Management-v6/Services/ContentService it is not but there must be a workaround so that I can bulk delete the old content created from the web service call and replace it with the most recent content.
I thought doing something like this would be possible:
cs.GetChildren(rootID).Where(x => x.DocumentTypeAlias == "weather" );
But according to my Visual Studio this appears to be invalid.
Any help would be greatly appreciated.
/Jason
This is entirely possible using the following syntax:
var weatherPages = cs.GetChildren(rootID).Where(x => x.ContentType.Alias == "weather");
Each of the matching pages can then be deleted using the following syntax:
foreach (var item in weatherPages){
cs.Delete(item);
}

Get list of invited friends from MultiFriendSelector

I am using ASP.net C# for a web application that integrates with the Facebook API. My application will allow users to create a group for sharing code. I need to use Facebook API to let the user invite friends from Facebook to join his group on my application. This is a requirement for an assignment so please don't give suggestions to create a group of users that are registered with my site only.
Until now I have the request dialog with all the friends listed (MultiFriendSelector()) with this code:
<p> Click <span id="span-link" onclick="sendRequestViaMultiFriendSelector(); return false;">here</span> to add friends from your Facebook account to your group! </p>
But I am stuck on how to get the id's and details of these invited users so I can save them in my database and allow them to access the group they were invited to. How can I do this please? I can't seem to find anything related to this.
By the way I know that there is a related question which gives this code:
if( Request["ids"] != null )
((Site)Master).FbInviteSent(Request.QueryString.GetValues("ids"));
but I don't know what Master is and I cant get it to work.
Thanks for your help :)
Whenever you call the request dialog, you may pass a callback function:
function sendRequestViaMultiFriendSelector() {
FB.ui({method: 'apprequests',
message: 'My Great Request'
}, requestCallback);
}
The requestCallback will receive the response, and this response returns the facebook id of the users, who were invited
function requestCallback(response){
for (var i = 0; i < response.to.length; i++) {
fb_id = response.to[i];
// Do something with fb_id.
}
}
From looking at the code in the other answer it looks like the facebook API will call back to your page with a query string parameter of ids.
I.e. It will call you site with a url like this.
http://wwww.yoursitesulr.com/mypage.aspx?ids=13,22,44
You can then pull out the id's from the query string using
string myIds = Request.QueryString["ids"];
You can then convert them to a array.
var ids = myIds.Split(',');
If you are using MVC then you can take advantage of the model binders and just put an int array in your view model and it will get bound automatically.
The answer below addresses your specific issie so I would use this as a starting point.
Faceboook: Posting to Multiple Friend's Walls Using Multiple Friend Selector and JS SDK
Let me know if you have any questions regarding the above solution.
Regards
Steve

post items from to amazon.com using API

What API I should use to post items from asp.net (C#) web application to amazon.com ?
please guide me to proper documentation and steps.
What I am looking for is how to add new item into certain category and pass the item title/description/pictures/price etc... -- plz advice
Thanks
You're question is a bit vague, but this was the most useful link I found when researching into how to interface with Amazon using C# -
http://flyingpies.wordpress.com/2009/08/01/17/
You need the Marketplace Web Services API. Found at http://developer.amazonservices.com.
You then need the flat file feed specifications to send the flat file in the correct format to the MWS. That can be found after you're logged into your seller central account:
https://sellercentral.amazon.com/gp/help/help.html/ref=ag_13461_cont_help?ie=UTF8&itemID=13461&language=en_US
From there, you can simply send to the MWS the data you need. Here is a snippet of my code:
SubmitFeedRequest req = new SubmitFeedRequest();
req.ContentMD5 = MarketplaceWebServiceClient.CalculateContentMD5(feedContent);
feedContent.Position = 0;
req.FeedContent = feedContent;
req.FeedType = "_POST_FLAT_FILE_INVLOADER_DATA_";
req.PurgeAndReplace = false;
req.Marketplace = MarketPlaceId;
req.Merchant = MerchantId;
return Service.SubmitFeed(req);
Assuming that by 'posting' you mean posting new items into the amazon marketplace, you can use
this api https://affiliate-program.amazon.com/gp/advertising/api/detail/main.html
Also google works wonders for searching
It sounds to me like you need the Amazon Market Place Feeds API.
https://developer.amazonservices.co.uk/gp/mws/api.html?ie=UTF8&section=feeds&group=bde&version=latest
You can use SubmitFeed to send product and inventory information to Amazon

Webpart: Impersonation / RunWithElevatedPrivileges

I am using MOSS 07 & VisualStudio 07 (c#) on a WindowsServer2003
My Problem is that I want to have access from one Sharepoint to another.
In SharePoint_1 is a SPList I want to read out from SharePoint_2.
The results of my research are IMPERSONATION and RUN_WITH_ELEVATED_PRIVILEGES.
With impersonation I can read out the html code of the SPSite I am connected with, but how can I get the List I want?
When I try to RunWithElevatedPrivileges I have to take a user form the site of SharePoint_1. But I cant get the User (even if I got his name) because of a FileNotFoundException.
How can I solve the problem?
Thanks
There is something I forgot to tell.
In the List are Attachments and I need access to them, too.
What would be the best way to solve this issue?
Hopefully its not very tricky, because I used Sharepoint 5 weeks ago the first time and dont so feel very familiar with it :)
Thanks
You dont need to specify a user when using SPSecurity.RunWithElevatedPrivileges. I think you will be ok if you use:
[url] = url to the other site collection
SPSecurity.RunWithElevatedPrivileges(() => {
using (var site = new SPSite("[url]")) {
using (var web = site.OpenWeb()) {
// Access list here
}
site.RootWeb.Dispose();
}
});

Categories

Resources