How to construct/get Office Web App URL for sharepoint documents - ios

I am trying to get the right redirection URL for my sharepoint documents which then I can use to open documents in WebView of iOS. Currently I am giving the absolute URL for the document where the doc is rendered inside WebView as PDF(Image/Readonly). Whereas I want to redirect to office webapp. Now my issue is I dont know if the URL for office web app is something which I can construct like appending /_layouts/15/WopiFrame.aspx?sourcedoc= or is the URL custom based on installations and we need to call some Sharepoint API which will let us know what is the base URL for Wopi service.
Currently I am passing URL like - https://.sharepoint.com/Shared%20Documents/demo/demo.docx
Whereas I want to pass URL like - https://.sharepoint.com/_layouts/15/WopiFrame.aspx?sourcedoc=/Shared%20Documents/demo/demo.docx
Looking forward for help.
Thanks in advance,
Vishwesh

File f = clientContext.Web.GetFileByServerRelativeUrl("/sites/ /Shared%20Documents/Title.docx");
clientContext.Load(f);
clientContext.ExecuteQuery();
ClientResult<String> result = f.ListItemAllFields.GetWOPIFrameUrl(SPWOPIFrameAction.Edit);
clientContext.Load(f.ListItemAllFields);
clientContext.ExecuteQuery();
result.Value contains a URL, something like this:
http://sharep.xxx:8080/sites/zxxx/_layouts/15/WopiFrame.aspx?sourcedoc=%2Fsites%2Fzxxx%2FShared%20Documents%2FTitle%2Edocx&action=edit
Also you can extract the extract Office Web Apps URL from the above page, if you don't want to hit the sharepoint at all.

using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Utilities;
// Assume we have these variables:
// ctx: A valid client context
// serverRelativeUrl: the URL of the document
File f = ctx.Web.GetFileByServerRelativeUrl (serverRelativeUrl);
result = f.ListItemAllFields.GetWOPIFrameUrl(SPWOPIFrameAction.Edit);
ctx.Load(f.ListItemAllFields);
ctx.ExecuteQuery();
This builds on the answer from #thebitlic which was the silver bullet for sure! However he or she is doing two calls to the server. Through the wonders of CSOM batching, it's possible to do it in one round trip, and no need to bring back the File object at all.

Related

Is there a way to x-callback from Telegram to another app?

I am creating a Telegram bot and need to x-callback to another application.
This is my x-callback that opens VLC and streams a video. It works fine when I use it in Siri Shortcuts or in Safari. But I need it to work on Telegram chat conversation.
vlc-x-callback://x-callback-url/stream?url=https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_1mb.mp4
When I send it as raw text it obviously doesn't recognize it as a valid url and does nothing.
I have tried to format it Markdown, MarkdownV2 and HTML styles but none works.
I've also tried InlineKeyboardButton giving it the text and url but it throws a BadRequest error
telegram.error.BadRequest: Inline keyboard button url is invalid
Is there any workaround to x-callback from Telegram to another app?
My question is implementation independent, but here is my code using python-telegram-bot
from telegram import Update, ParseMode, InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import CommandHandler, CallbackContext, Updater
my_x_callback = 'vlc-x-callback://x-callback-url/stream?url=https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_1mb.mp4'
def test(update: Update, context: CallbackContext):
update.message.reply_text(my_x_callback)
update.message.reply_text(f'[Play it on VLC]({my_x_callback})', parse_mode=ParseMode.MARKDOWN)
update.message.reply_text(f'[Play it on VLC]({my_x_callback})', parse_mode=ParseMode.MARKDOWN_V2)
update.message.reply_text(f'Play it on VLC', parse_mode=ParseMode.HTML)
button = InlineKeyboardButton('Play it on VLC', url=my_x_callback)
update.message.reply_text(
'Testing InlineKeyboard',
reply_markup=InlineKeyboardMarkup([[button]])
)
if __name__ == '__main__':
updater = Updater('TOKEN')
updater.dispatcher.add_handler(CommandHandler('test', test))
updater.start_polling()
updater.idle()
I had a similar use case once where I wanted to use mailto: links. My workaround is to create a website URL that points to the mailto: link. I.e. flow is:
Generate mailto link depending on users request
Generate https:// url that points to the link - in my case that's done via a self-hosted YOURLS instance
used that generated URL either for an inline buttton or as text link.

How to get the shared file with Microsoft Graph?

I want to share files from MS OneDrive to a user via MS graph API. And user can view my shared file directly through the link. I have read the Document of Creating a sharing Link for a DriveItem and use this API to create a sharing link for my sharing files.
I wonder how to implement with MS graph API? Any suggestion and tips are welcome. Thanks
According to your description, I assume you want to get the share file by using MS Graph API.
Base on my test, We can create a shareLink for this this file.
Then we can use the following steps to get the file information by converting the shareLink.
Encoding the shareLink by using the following logic:
1)First, use base64 encode the URL.
2)Convert the base64 encoded result to unpadded base64url format by removing = characters from the end of the value, replacing / with _ and + with -.)
3)Append u! to be beginning of the string.
If you want access the shared files, you can use the following API:
GET /shares/{shareIdOrUrl}/driveItem
The shareIdOrUrl parameter is the result in step1.
This API will return all the information about the shared file.
As an example, to encode a URL in C#:
string sharingUrl = "https://onedrive.live.com/redir?resid=1231244193912!12&authKey=1201919!12921!1";
string base64Value = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(sharingUrl));
string encodedUrl = "u!" + base64Value.TrimEnd('=').Replace('/','_').Replace('+','-');
For more detail, we can refer to this document.

Crystal-lang: How to Find End URL After a Redirect?

I'm just dipping a toe in the water with Crystal at the moment and, as an exercise, trying to port one of my Python scripts across.
The script in question downloads the 'latest' PDF from a URL which takes the form: "http://somesite.com/download/latest/". When visited that URL automatically redirects to the page for the latest download eg. "http://somesite.com/download/4563/"
I'm having difficulty working out how to implement this in Crystal so that I can grab the actual URL that the redirect ends up on.
In Python I do:
currenturl = urllib.request.urlopen(latesturl)
#above will redirect to URL of format http://somesite.com/download/XXXXX/
#where XXXXX is the current d/load
endurl = currenturl.geturl()
...which gives me the end URL in the "endurl" variable.
But, reading the docs for Crystal's "http/client" I can't see any way to return the actual URL that a redirect ends up on. Is it possible?
Crystal's HTTP::Client currently can't automatically follow redirects.
Please note that you're reading an outdated version of the API docs, the current is at https://crystal-lang.org/api/latest/HTTP/Client.html (I don't think there have been relevant changes between 0.24.1 and 0.26.1 though).
But you can easily access the redirect URL from reading the Location header of an HTTP response:
response = HTTP::Client.get latesturl
endurl = response.headers["Location"]

uploading a file from iOS mobile application to SharePoint

I'm working on a SharePoint mobile solution where I'm using the web services exposed in server/_vti_bin/sitedata.asmx, server/_vti_bin/Lists.asmx and server/_vti_bin/copy.asmx.
I'm able to successfully fetch the list of sites, document libraries and files using the services defined in server/_vti_bin/sitedata.asmx.
Now I'm actually trying to upload an image file from Photo Albums available in iOS to SharePoint. For this, I tried using CopyIntoItems web service, where in I'm getting the following error response.
<CopyResult ErrorCode="DestinationInvalid" ErrorMessage="The Copy web service method must be called on the same domain that contains the destination url." DestinationUrl="http://xxxxserveripxxxxxx/Shared Documents/image1.png"/>
But came to know that this service is used only if the file to be uploaded is also from the same source(i.e., from sharepoint).
Is there any other way to upload a file available in iPhone to SharePoint.
Also tired addAttachment service defiend in server/_vti_bin/Lists.asmx but I'm unable to identify the input parameters which requires list name and list Item ID.
I'm trying to upload a file to Shared Documents, so I've List Name value which is the one in curly braces of Shared Documents but now what should be the List Item Id value?
These are the details I've with regard to "Shared Documents" document library.
{
AllowAnonymousAccess = false;
AnonymousViewListItems = false;
BaseTemplate = DocumentLibrary;
BaseType = DocumentLibrary;
DefaultViewUrl = "/Shared Documents/Forms/AllItems.aspx";
Description = "Share a document with the team by adding it to this document library.";
InheritedSecurity = true;
InternalName = "{425F837A-F110-4876-98DE-C92902446935}";
LastModified = "2013-07-26 20:09:58Z";
ReadSecurity = 1;
Title = "Shared Documents";
},
So, I'm using the using InternalName value for listName tag.
What should be the value of listItemID?
Am I going in the right way or is there any other approach to upload a local file from mobile to SharePoint?
Thanks
Sudheer
Are you actually calling a URL or are you using the IP (you x'ed it out and said server IP)? If you don't have Alternate Access Mappings defined for the IP, uploads will fail but the GET requests will generally work ok.

native Domino links and XPages

Users open documents by links in old format http://server/db.nsf/VIEW_UNID/DOC_UNID. The form has property set to open XPage instead.
Origin of these links is email notification generated by "universal agent". It simply sends link to document. It does not know, what form is associated with what XPage, therefore it generates universal links instead of "/page.xsp&documentId=...".
The problem: relative links computed at client do not work - < a href = "/page.xsp?params"> should be more effective - no roundtrip and easy to compute at page load. They evaluate to http://server/db.nsf/0/page.xsp?params, what ends with Error 404, naturaly.
XPage contains "help" section, what is another document with RT field containing text, images and links. And relative links in that RT field work when XPage is opened from another XPage - view (/page.xsp), but fail when redirected from notification link (/0/UNID).
Question: How to effectively reset browser's address bar to extended XPages format http://server/db.nsf/page.xsp?documentId=DOC_UNID after opening redirected documents/views by old fashioned URLs?
Main problem is in discrepancy of relative links on server side (evaluated in SSJS) and client side (evaluated by browser). I have solved my problem by simple redirect in case document is open by old fashioned link.
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:eventHandler event="onClientLoad" submit="false">
<xp:this.script><![CDATA[var url = "#{javascript:context.getUrl()}";
var l = window.location;
if (url != l) {
window.location.replace(url);
}
]]></xp:this.script>
</xp:eventHandler>
</xp:view>
Simply said, if open URL differs from internal URL (as resolved by XSP engine), browser redirects to correct URL. This solved many problems we had with inline images (image resource) and attachments.
Try "./page.xsp&params" or ../ if you want to go back to the root - I have noticed IBM do this in their coding as well. Hope this helps.
Have you tried to set pageBaseUrl property in your XPages? This would help to repair the relativ links:
<xp:this.pageBaseUrl>
<xp:baseUrl>
<xp:this.href><![CDATA[#{javascript:"http://stackoverflow.com/"}]]></xp:this.href>
</xp:baseUrl>
</xp:this.pageBaseUrl>
Another idea is to do a redirect in beforePageLoad-event in the XPage if the URL is in old fashioned style.

Resources