I am trying to get the preview URL for various items in SharePoint. When viewing an image, something like this will work:
var sharePointServerUri = new Uri( item.Context.Url );
var sharePointFileUrl =
HttpUtility.UrlEncode( string.Format( "{0}://{1}{2}", sharePointServerUri.Scheme, sharePointServerUri.Host, item.File.ServerRelativeUrl ) );
var lightBoxShareUrl = string.Format( "{0}_layouts/15/Lightbox.aspx?url={1}", sharePointServerUri.AbsoluteUri, sharePointFileUrl );
However, this doesn't work for something like a Word document, only images/videos.
Is there a better way to do this which will handle all file types using the SharePoint API?
I was able to get a preview link by doing something like this:
Microsoft.SharePoint.Client.ClientContext clientContext;
Microsoft.SharePoint.Client.ListItem item;
var wopiFrameUrl = item.GetWOPIFrameUrl( Microsoft.SharePoint.Client.SPWOPIFrameAction.InteractivePreview );
clientContext.ExecuteQuery();
And the wopiFrameUrl.Value is the preview URL. It seems that it would come back null if the item is an image, in which case I used the code from the question to construct a LightBox URL.
Related
Ok am am very new to Umbraco/C# and what I am trying to do is loop through a custom media type to build banners for the home page of my application and the #bannerUrl always returns the images property id and not the file path to the resource. How would you go about retrieving the image file path from a custom media type created in Umbraco.
See code for example:
var mediaFolder = Umbraco.Media(mediaFolderId);
var banners = mediaFolder.Children();
foreach (var banner in banners)
{
var bannerUrl = banner.image;
<div style="background-image:url(#bannerUrl);"></div>
}
The variable bannerUrl always returns the image id by default and not the file path for the URL. How can I get the file path working? When inspecting the contents of the banner object in the debugger in VS I notice of the Url property has the following error:
Url = 'banner.Url' threw an exception of type 'System.NotSupportedException'
You would of though I could use something along the .Url lines but that dose not seem to work, so any suggestions how I would go about getting the URL the image property in Umbraco using the Dynamic way.
Thanks.
Solutioin if anyone happens to stumbles upon this:
var bannerId = Umbraco.Media(banner.image); //banner.image is the property id.
var bannerUrl = bannerId.Url;
To do the same within an MVC controller / API Contoller once you have the "media ID" you can also use the UmbracoHelper.
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
var image = umbracoHelper.Media(mediaID); // mediaID = the (int)ID of the media
var imageURL = image.url; // imageURL now has the site root relative path of the media item
It's much better to use strongly typed models in Umbraco nowadays:
var bannerMediaItem = Umbraco.TypedMedia(banner.image); //banner.image is the property id.
var bannerUrl = bannerMediaItem.Url;
I would like to know the page views for a certain page/url only.
Is there a way to add the url to the Google query? Baseurl doesn't seem to work.
DataQuery PageViewQuery = new DataQuery(DataFeedUrl)
{
Ids = ProfileID,
Dimensions = "ga:date",
Metrics = "ga:pageviews",
Sort = "ga:date",
GAStartDate = (DateTime.Now).AddDays(-7).ToString("yyyy-MM-dd"),
GAEndDate = (DateTime.Now).ToString("yyyy-MM-dd")
};
You might try ga:pagePath (plus ga:hostname if you need to retrieve a full URL), or if you have unique page titles ga:pageTitle should be a valid workaround.
Full documentation of dimensions and metric is here: https://developers.google.com/analytics/devguides/reporting/core/dimsmets.
Using C# , I want to read the Shares , Comments and Likes of a Google + post like this https://plus.google.com/107200121064812799857/posts/GkyGQPLi6KD
That post is an activity. This page includes infomation on how to get infomation about activities. This page gives some examples of using the API. This page has downloads for the Google API .NET library, which you can use to access the Google+ APIs, with XML documentation etc.
You'll need to use the API Console to get an API key and manage your API usage.
Also take a look at the API Explorer.
Here's a working example:
Referencing Google.Apis.dll and Google.Apis.Plus.v1.dll
PlusService plus = new PlusService();
plus.Key = "YOURAPIKEYGOESHERE";
ActivitiesResource ar = new ActivitiesResource(plus);
ActivitiesResource.Collection collection = new ActivitiesResource.Collection();
//107... is the poster's id
ActivitiesResource.ListRequest list = ar.List("107200121064812799857", collection);
ActivityFeed feed = list.Fetch();
//You'll obviously want to use a _much_ better way to get
// the activity id, but you aren't normally searching for a
// specific URL like this.
string activityKey = "";
foreach (var a in feed.Items)
if (a.Url == "https://plus.google.com/107200121064812799857/posts/GkyGQPLi6KD")
{
activityKey = a.Id;
break;
}
ActivitiesResource.GetRequest get = ar.Get(activityKey);
Activity act = get.Fetch();
Console.WriteLine("Title: "+act.Title);
Console.WriteLine("URL:"+act.Url);
Console.WriteLine("Published:"+act.Published);
Console.WriteLine("By:"+act.Actor.DisplayName);
Console.WriteLine("Annotation:"+act.Annotation);
Console.WriteLine("Content:"+act.Object.Content);
Console.WriteLine("Type:"+act.Object.ObjectType);
Console.WriteLine("# of +1s:"+act.Object.Plusoners.TotalItems);
Console.WriteLine("# of reshares:"+act.Object.Resharers.TotalItems);
Console.ReadLine();
Output:
Title: Wow Awesome creativity...!!!!!
URL:http://plus.google.com/107200121064812799857/posts/GkyGQPLi6KD
Published:2012-04-07T05:11:22.000Z
By:Funny Pictures & Videos
Annotation:
Content: Wow Awesome creativity...!!!!!
Type:note
# of +1s:210
# of reshares:158
I'm trying to allow users to post videos on my site by supplying only the URL. Right now I'm able to allow YouTube videos by just parsing the URL and obtaining the ID, and then inserting that ID into their given "embed" code and putting that on the page.
This limits me to only YouTube videos however, what I'm looking to do is something similar to facebook where you can put in the YouTube "Share" URL OR the url of the page directly, or any other video url, and it loads the video into their player.
Any idea how they do this? or any other comparable way to just show a video based just on a URL? Keep in mind that youtube videos (which would probably be most popular anyway) don't give the video url, but the url to the video on the YouTube page (which is why their embed code is needed with just the ID).
Hopefully this made sense, and I hope somebody might be able to offer me some advice on where to look!
Thanks guys.
I would suggest adding support for OpenGraph attributes, which are common among content services which work to enable other sites to embed their content. The information on the pages will be contained in their <meta> tags, which means you would have to load the URL via something like the HtmlAgilityPack:
var doc = new HtmlDocument();
doc.Load(webClient.OpenRead(url)); // not exactly production quality
var openGraph = new Dictionary<string, string>();
foreach (var meta in doc.DocumentNode.SelectNodes("//meta"))
{
var property = meta["property"];
var content = meta["content"];
if (property != null && property.Value.StartsWith("og:"))
{
openGraph[property.Value]
= content != null ? content.Value : String.Empty;
}
}
// Supported by: YouTube, Vimeo, CollegeHumor, etc
if (openGraph.ContainsKey("og:video"))
{
// 1. Get the MIME Type
string mime;
if (!openGraph.TryGetValue("og:video:type", out mime))
{
mime = "application/x-shockwave-flash"; // should error
}
// 2. Get width/height
string _w, _h;
if (!openGraph.TryGetValue("og:video:width", out _w)
|| !openGraph.TryGetValue("og:video:height", out _h))
{
_w = _h = "300"; // probably an error :)
}
int w = Int32.Parse(_w), h = Int32.Parse(_h);
Console.WriteLine(
"<embed src=\"{0}\" type=\"{1}\" width=\"{2}\" height=\"{3}\" />",
openGraph["og:video"],
mime,
w,
h);
}
Not sure if this is asked, but searching hasn't quite yielded what I'm looking for. I have a page layout already, what I need to do is programmatically create a page in the Pages library.
I'm fuzzy on the details, but somehow I think I will need to open the Layout, then stream it to a page and then save the page. I'm unsure how to go about this.
The page is context sensitive so I think I'll begin with using SPSite and SPWeb to get access to the lists.
What I'm unclear on is, how can I get the Layouts? I think I should be able to add a page somewhat like this:
SPWeb web = SPContext.Current.Site.OpenWeb();
SPList Pages = web.Lists["Pages"];
SPListItemCollection splc = Pages.Items;
foreach (SPListItem spli in splc)
{
if (spli.Name == "lmIntraTopicsArticle")
{
}
}
SPListItem sli = splc.Add();
Pages.Update();
SPFolder PagesFolder = Pages.RootFolder;
byte[] layoutContents = new byte[20];
SPFile myNewPage = PagesFolder.Files.Add(PagesFolder.Url + "/TopicWindowArchive.aspx", layoutContents);
web.Update();
Now I need to figure out how to add content from a layout. Update in a few if I figure it out.
Thank you,
The trick is to get a PublishingWeb object. That contains the layouts.
See here for an example
PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
string pageName = “MyCustomPage.aspx”;
PageLayout[] pageLayouts = publishingWeb.GetAvailablePageLayouts();
PageLayout currPageLayout = pageLayouts[0];
PublishingPageCollection pages = publishingWeb.GetPublishingPages();
PublishingPage newPage = pages.Add(pageName,currPageLayout);
newPage.ListItem[FieldId.PublishingPageContent] = “This is my content”;
newPage.ListItem.Update();
newPage.Update();
newPage.CheckIn(“This is just a comment”);
Also check this answer