SharepointDriveItem Preview URL to pen the document preview in SharePoint - c#

I need to generate the preview URL of a document in SharePoint. For that I'm using the following code:
GraphServiceClient graphClient = await graphProvider.GetGraphServiceClient(authObject);
var preview = await graphClient.Sites[siteId].Drives[driveId].Items[graphId].Preview().Request().PostAsync();
return preview.GetUrl;
But the problem is that the above code is returning the embedded URL ( https://myDomain.sharepoint.com/sites/***********/_layouts/15/embed.aspx?uniqueId=2436cab2-0727-4480-9750-*******&access_token=****) which is opening in OneDrive instead of SharePoint.
As per MSDNThe preview action is currently only available on SharePoint and OneDrive for Business. So My question is, What's the change we need to do to get the preview in SharePoint?

Related

Why does MS Graph Thumbnail URL change after document changes

I am using MS Graph c# SDK to pull the thumbnail links for some docx and pdf files. The issue I was planning to store these links in my db to call them quickly for the front end. However, I noticed anytime a document is saved the link changes. However, the old URL still works and it also includes the latest changes. Is it safe to store the URLs and reuse them or does it not matter as my current experiment is showing:
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var thumbnails = await graphClient.Me.Drive.Items["{driveItem-id}"].Thumbnails
.Request()
.GetAsync();
The URLs change to ensure that browser will invalidate their cache and render an updated thumbnail. We generally don't recommend caching the URLs yourself because there may be scenarios that trigger an expiration of the URL, at which point what you have cached will fail to work. However, as long as you handle failures of cache URLs by falling back to getting a new thumbnail URL maybe it'll be ok for your scenario.

How do I upload an image to cloudinary in ASP.NET MVC app?

I'm using ASP.NET 4.7.2 MVC framework. I need to upload images using cloudinary and save the url of that image in my database. The problem is, Cloudinary's dot net documentation is a bit confusing as they have just declared a function. How do I make call to that function from my view? I have no idea.
Basically, I have a form and in there I want to add an option for uploading images (which should be done using cloudinary service) and then save the url of the uploaded image in my DB. I have no idea how to achieve that since their documentation only mentions just a function like so:
var uploadParams = new ImageUploadParams()
{
File = new FileDescription(#"c:\my_image.jpg")
};
var uploadResult = cloudinary.Upload(uploadParams);
What do I do with this function and how to use it to add image uploading functionality? Please, help me out. Thanks.
Uploading an asset to Cloudinary can be done either directly from the client-side (i.e., from the View of your application) or through the use of the server-side SDK (i.e., from the Controller of your application).
If you intend to perform the image uploading using the CloudinaryDotNet SDK (https://github.com/cloudinary/CloudinaryDotNet), you will need to submit the image file from the View back to the Controller of your application. And in the controller method, you can invoke the SDK methods to perform the actual image upload to Cloudinary server.
There is a sample project enclosed in the SDK source, which can be found in this link: https://github.com/cloudinary/CloudinaryDotNet/tree/master/samples.

Microsoft Graph .NET Client Library: Upload file to document center

I want to create a file in a Sharepoint document center using Microsoft Graph .NET Client Library. It seems that I can successfully create the file but it is not visible to anyone except the app which created it. When the app creates a file in an "ordinary" document library with exactly the same code then the file is visible to other users (as expected).
Here is the code I use:
var result = await client.Drives[documentCenterDriveId]
.Items[subfolderId]
.ItemWithPath(fileName)
.Content
.Request()
.PutAsync<DriveItem>(new MemoryStream(buffer));
Afterwards I can query the folder and see that the file is there:
var result = await client.Drives[documentCenterDriveId]
.Items[subfolderId]
.Children
.Request()
.GetAsync();
However when go to the Microsoft Graph Explorer, sign in with my personal credentials (i.e. not the same as the app) and issue the following GET request
https://graph.microsoft.com/v1.0/drives/documentCenterDriveId/items/subfolderId/children
I get an empty list. If I do the same for the "ordinary" document library it works as expected.
I checked the permissions of the file in the document center with
var perms = await client.Drives[documentCenterDriveId]
.Items[fileId]
.Permissions
.Request()
.GetAsync();
and the read role is granted to a group my account belongs to. This means I should be able to see it.
How can I diagnose the source of this issue? Are there logs somewhere in Sharepoint where I could find out more? There are no error messages or exceptions when I run my code.
I found out that I also have to checkin the file.
await client.Drives[documentCenterDriveId].Items[result.Id].Checkin().Request().PostAsync();
I don't know why I do not need to checkin the file after upload in a "ordinary" document library but in the document center I have to.

How to get video file stream from embed url in c#

I tried this below code but video is not playing.
var httpClient = new HttpClient();
var data = await httpClient.GetByteArrayAsync(new Uri("http://www.youtube.com/embed/iRFE-sKOp4I"));
var file = await KnownFolders.MusicLibrary.CreateFileAsync("myfile.mp4", CreationCollisionOption.ReplaceExisting);
var targetStream = await file.OpenAsync(FileAccessMode.ReadWrite);
await targetStream.AsStreamForWrite().WriteAsync(data, 0, data.Length);
await targetStream.FlushAsync();
targetStream.Dispose();
Any one please help me to how to save download..thankyou
I agree with #x..., If you want to download video from Youtube, you need to install the YoutubeExtractor.
But with that same code i can't to download different website videos.
I tested your code with a video download uri "http://video.ch9.ms/ch9/9b56/4f2d0b4d-ea37-4525-8833-128ad6e69b56/uwp01SeriesIntro.mp4", it works fine.
Actually I want to download openload.co/embed/EHmDelqNx94 video is there any possibility..
I just took a look at this video, I find this a web named openload, and this web service share free without limits, but you need to use the develop Api of it. For downloading, you can refer to the download APIs here.
the video url appears after click on play button, is there any way to handle click event by httpclient or any other clients
From the official document of this web, I found this:
get a download link by using download ticket.
You can refer to Download Link.
Update:
i tried openload api, but when get download link it showing captcha error, can you please help me for this
I just reproduced your problem, this is because your source for download is not a public source, it needed authentication. When you get the Download Ticket for download, although the Api said API-Login and API-Key are not required, you need to use the full path https://api.openload.co/1/file/dlticket?file={file}&login={login}&key={key} to get an authenticated ticket, then you can use this ticket to get the download URL.

Retrieve photos from Facebook/Instagram

I am looking to retrieve photos from Facebook and Instagram for viewing in a WPF application. The idea behind is to show user existing photos and allow them to upload more using C#. A bonus would be to let the user delete photos and set their profile picture, but is not a must.
I cannot find any APIs for either Facebook or Instagram for use in a WPF application, and the ones I did find were all for web (ASP.NET/PHP).
Is there such an API and how might I go about doing this?
Looks like they have what you're looking for in the Graph API:
https://developers.facebook.com/docs/graph-api/reference/user/photos/
Facebook Graph .NET API.
Using the Facebook .NET SDK
Here is an example I whipped up, haven't tested. Should work though. It retrieves the profile picture of a user. Though if you read through the APIs you can adapt it for whatever you need.
var client = new FacebookClient("accessToken");
object taskResult = await client.GetTaskAsync("/me");
var result = (IDictionary<string, object>)taskResult;
var userId = taskResult.Where(s=>s.Key == "id").First().Value
var profilePicUrl = string.Format("https://graph.facebook.com/{0}/picture", userId);
Facebook SDK
For instagram
This link will help you embeding the instagram on a simple html webpage.
There is a button on the bottom of the post on instagram.when you click on the link a menu pops up. then click on embed
now a box pops up
just copy paste the html and you are done.
it will fetch the post for you

Categories

Resources