How to open file .doc use “Word” app on Xamarin Forms?
Use Xamarin Forms and on iOS, how to check and open Word app when Open file by UrL?
Reference: https://docs.microsoft.com/en-us/office/client-developer/integration/integrate-with-office-from-ios-applications
This is my code, it isn't work:
Device.OpenUri(new Uri("ms-word:ofe|u|https://calibre-ebook.com/downloads/demos/demo.docx"));
Please help me!
Thanks!
xamarin xamarin.forms xamarin.ios
|
show 1 more comment
Use Xamarin Forms and on iOS, how to check and open Word app when Open file by UrL?
Reference: https://docs.microsoft.com/en-us/office/client-developer/integration/integrate-with-office-from-ios-applications
This is my code, it isn't work:
Device.OpenUri(new Uri("ms-word:ofe|u|https://calibre-ebook.com/downloads/demos/demo.docx"));
Please help me!
Thanks!
xamarin xamarin.forms xamarin.ios
You need a dependency service for this its not a xamarin forms thing!
– G.hakim
Nov 22 at 12:05
I want write code on iOS. You can supply solution @G.hakim
– Huu Bao Nguyen
Nov 22 at 12:07
I guess this guide here has necessary information.
– G.hakim
Nov 22 at 12:43
I only want that view file .doc on external app ("Word" app itunes.apple.com/us/app/microsoft-word/id586447913?mt=8). May be your solution don't fit with me.
– Huu Bao Nguyen
Nov 22 at 15:25
I find a answer is same with your answer stackoverflow.com/questions/51494932/… But you don't want "edit" file, Do you only want "view" file .docx with Word app?when open it to your app.
– user10666363
Nov 22 at 16:04
|
show 1 more comment
Use Xamarin Forms and on iOS, how to check and open Word app when Open file by UrL?
Reference: https://docs.microsoft.com/en-us/office/client-developer/integration/integrate-with-office-from-ios-applications
This is my code, it isn't work:
Device.OpenUri(new Uri("ms-word:ofe|u|https://calibre-ebook.com/downloads/demos/demo.docx"));
Please help me!
Thanks!
xamarin xamarin.forms xamarin.ios
Use Xamarin Forms and on iOS, how to check and open Word app when Open file by UrL?
Reference: https://docs.microsoft.com/en-us/office/client-developer/integration/integrate-with-office-from-ios-applications
This is my code, it isn't work:
Device.OpenUri(new Uri("ms-word:ofe|u|https://calibre-ebook.com/downloads/demos/demo.docx"));
Please help me!
Thanks!
xamarin xamarin.forms xamarin.ios
xamarin xamarin.forms xamarin.ios
edited Nov 22 at 15:49
asked Nov 22 at 11:21
Huu Bao Nguyen
15112
15112
You need a dependency service for this its not a xamarin forms thing!
– G.hakim
Nov 22 at 12:05
I want write code on iOS. You can supply solution @G.hakim
– Huu Bao Nguyen
Nov 22 at 12:07
I guess this guide here has necessary information.
– G.hakim
Nov 22 at 12:43
I only want that view file .doc on external app ("Word" app itunes.apple.com/us/app/microsoft-word/id586447913?mt=8). May be your solution don't fit with me.
– Huu Bao Nguyen
Nov 22 at 15:25
I find a answer is same with your answer stackoverflow.com/questions/51494932/… But you don't want "edit" file, Do you only want "view" file .docx with Word app?when open it to your app.
– user10666363
Nov 22 at 16:04
|
show 1 more comment
You need a dependency service for this its not a xamarin forms thing!
– G.hakim
Nov 22 at 12:05
I want write code on iOS. You can supply solution @G.hakim
– Huu Bao Nguyen
Nov 22 at 12:07
I guess this guide here has necessary information.
– G.hakim
Nov 22 at 12:43
I only want that view file .doc on external app ("Word" app itunes.apple.com/us/app/microsoft-word/id586447913?mt=8). May be your solution don't fit with me.
– Huu Bao Nguyen
Nov 22 at 15:25
I find a answer is same with your answer stackoverflow.com/questions/51494932/… But you don't want "edit" file, Do you only want "view" file .docx with Word app?when open it to your app.
– user10666363
Nov 22 at 16:04
You need a dependency service for this its not a xamarin forms thing!
– G.hakim
Nov 22 at 12:05
You need a dependency service for this its not a xamarin forms thing!
– G.hakim
Nov 22 at 12:05
I want write code on iOS. You can supply solution @G.hakim
– Huu Bao Nguyen
Nov 22 at 12:07
I want write code on iOS. You can supply solution @G.hakim
– Huu Bao Nguyen
Nov 22 at 12:07
I guess this guide here has necessary information.
– G.hakim
Nov 22 at 12:43
I guess this guide here has necessary information.
– G.hakim
Nov 22 at 12:43
I only want that view file .doc on external app ("Word" app itunes.apple.com/us/app/microsoft-word/id586447913?mt=8). May be your solution don't fit with me.
– Huu Bao Nguyen
Nov 22 at 15:25
I only want that view file .doc on external app ("Word" app itunes.apple.com/us/app/microsoft-word/id586447913?mt=8). May be your solution don't fit with me.
– Huu Bao Nguyen
Nov 22 at 15:25
I find a answer is same with your answer stackoverflow.com/questions/51494932/… But you don't want "edit" file, Do you only want "view" file .docx with Word app?when open it to your app.
– user10666363
Nov 22 at 16:04
I find a answer is same with your answer stackoverflow.com/questions/51494932/… But you don't want "edit" file, Do you only want "view" file .docx with Word app?when open it to your app.
– user10666363
Nov 22 at 16:04
|
show 1 more comment
2 Answers
2
active
oldest
votes
What you are asking here can be done using a simple WebView in iOS:
First, create a custom WebView class that allows you to pick file uri:
public class CustomWebView : WebView
{
public static readonly BindableProperty UriProperty = BindableProperty.Create(propertyName: "Uri",
returnType: typeof(string),
declaringType: typeof(CustomWebView),
defaultValue: default(string));
public string Uri
{
get { return (string)GetValue(UriProperty); }
set { SetValue(UriProperty, value); }
}
}
Then in ios make a renderer for the same and do something like this:
[assembly: ExportRenderer (typeof(CustomWebView), typeof(CustomWebViewRenderer))]
namespace DisplayPDF.iOS
{
public class CustomWebViewRenderer : ViewRenderer<CustomWebView, UIWebView>
{
protected override void OnElementChanged (ElementChangedEventArgs<CustomWebView> e)
{
base.OnElementChanged (e);
if (Control == null) {
SetNativeControl (new UIWebView ());
}
if (e.OldElement != null) {
// Cleanup
}
if (e.NewElement != null) {
var customWebView = Element as CustomWebView;
string fileName = Path.Combine (NSBundle.MainBundle.BundlePath, string.Format ("Content/{0}", WebUtility.UrlEncode (customWebView.Uri)));
Control.LoadRequest (new NSUrlRequest (new NSUrl (fileName, false)));
Control.ScalesPageToFit = true;
}
}
}
}
Then use the custom control like this:
<local:CustomWebView Uri="FooPath" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />
Where FooPath is the path for the doc file.
add a comment |
I have solution for my project, I try it:
If you only open file .docx on iOS, you could write code at Share Code of iOS:
Check device of user has setup app (Word, Excel, PP, etc...)
public static bool HasSetupAppDocument(string extension)
{
if (string.IsNullOrEmpty(extension))
return false;
// Device has setup app?
var result = UIApplication.SharedApplication.CanOpenUrl(NSUrl.FromString($"{extension}"));
return result;
}
(Ex: extension
is ms-word:
or ms-excel:
or ms-excel:
Reference: https://docs.microsoft.com/en-us/office/client-developer/integration/integrate-with-office-from-ios-applications#office-protocols)
Notes: Add source to Info.plist
:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>ms-word</string>
<string>ms-excel</string>
<string>ms-powerpoint</string>
</array>
At Class Dependencies, open file with
URL
:
Device.OpenUri(new Uri($"{convertExtension}{url}"));
Note: url
is link file share on Onedrive and Be sure that account Onedrive as same as account login Word
app (if you had set security).
If file has mode Read-only
, app Word
will open file with mode Read-only
.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53429843%2fhow-to-open-file-doc-use-word-app-on-xamarin-forms%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
What you are asking here can be done using a simple WebView in iOS:
First, create a custom WebView class that allows you to pick file uri:
public class CustomWebView : WebView
{
public static readonly BindableProperty UriProperty = BindableProperty.Create(propertyName: "Uri",
returnType: typeof(string),
declaringType: typeof(CustomWebView),
defaultValue: default(string));
public string Uri
{
get { return (string)GetValue(UriProperty); }
set { SetValue(UriProperty, value); }
}
}
Then in ios make a renderer for the same and do something like this:
[assembly: ExportRenderer (typeof(CustomWebView), typeof(CustomWebViewRenderer))]
namespace DisplayPDF.iOS
{
public class CustomWebViewRenderer : ViewRenderer<CustomWebView, UIWebView>
{
protected override void OnElementChanged (ElementChangedEventArgs<CustomWebView> e)
{
base.OnElementChanged (e);
if (Control == null) {
SetNativeControl (new UIWebView ());
}
if (e.OldElement != null) {
// Cleanup
}
if (e.NewElement != null) {
var customWebView = Element as CustomWebView;
string fileName = Path.Combine (NSBundle.MainBundle.BundlePath, string.Format ("Content/{0}", WebUtility.UrlEncode (customWebView.Uri)));
Control.LoadRequest (new NSUrlRequest (new NSUrl (fileName, false)));
Control.ScalesPageToFit = true;
}
}
}
}
Then use the custom control like this:
<local:CustomWebView Uri="FooPath" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />
Where FooPath is the path for the doc file.
add a comment |
What you are asking here can be done using a simple WebView in iOS:
First, create a custom WebView class that allows you to pick file uri:
public class CustomWebView : WebView
{
public static readonly BindableProperty UriProperty = BindableProperty.Create(propertyName: "Uri",
returnType: typeof(string),
declaringType: typeof(CustomWebView),
defaultValue: default(string));
public string Uri
{
get { return (string)GetValue(UriProperty); }
set { SetValue(UriProperty, value); }
}
}
Then in ios make a renderer for the same and do something like this:
[assembly: ExportRenderer (typeof(CustomWebView), typeof(CustomWebViewRenderer))]
namespace DisplayPDF.iOS
{
public class CustomWebViewRenderer : ViewRenderer<CustomWebView, UIWebView>
{
protected override void OnElementChanged (ElementChangedEventArgs<CustomWebView> e)
{
base.OnElementChanged (e);
if (Control == null) {
SetNativeControl (new UIWebView ());
}
if (e.OldElement != null) {
// Cleanup
}
if (e.NewElement != null) {
var customWebView = Element as CustomWebView;
string fileName = Path.Combine (NSBundle.MainBundle.BundlePath, string.Format ("Content/{0}", WebUtility.UrlEncode (customWebView.Uri)));
Control.LoadRequest (new NSUrlRequest (new NSUrl (fileName, false)));
Control.ScalesPageToFit = true;
}
}
}
}
Then use the custom control like this:
<local:CustomWebView Uri="FooPath" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />
Where FooPath is the path for the doc file.
add a comment |
What you are asking here can be done using a simple WebView in iOS:
First, create a custom WebView class that allows you to pick file uri:
public class CustomWebView : WebView
{
public static readonly BindableProperty UriProperty = BindableProperty.Create(propertyName: "Uri",
returnType: typeof(string),
declaringType: typeof(CustomWebView),
defaultValue: default(string));
public string Uri
{
get { return (string)GetValue(UriProperty); }
set { SetValue(UriProperty, value); }
}
}
Then in ios make a renderer for the same and do something like this:
[assembly: ExportRenderer (typeof(CustomWebView), typeof(CustomWebViewRenderer))]
namespace DisplayPDF.iOS
{
public class CustomWebViewRenderer : ViewRenderer<CustomWebView, UIWebView>
{
protected override void OnElementChanged (ElementChangedEventArgs<CustomWebView> e)
{
base.OnElementChanged (e);
if (Control == null) {
SetNativeControl (new UIWebView ());
}
if (e.OldElement != null) {
// Cleanup
}
if (e.NewElement != null) {
var customWebView = Element as CustomWebView;
string fileName = Path.Combine (NSBundle.MainBundle.BundlePath, string.Format ("Content/{0}", WebUtility.UrlEncode (customWebView.Uri)));
Control.LoadRequest (new NSUrlRequest (new NSUrl (fileName, false)));
Control.ScalesPageToFit = true;
}
}
}
}
Then use the custom control like this:
<local:CustomWebView Uri="FooPath" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />
Where FooPath is the path for the doc file.
What you are asking here can be done using a simple WebView in iOS:
First, create a custom WebView class that allows you to pick file uri:
public class CustomWebView : WebView
{
public static readonly BindableProperty UriProperty = BindableProperty.Create(propertyName: "Uri",
returnType: typeof(string),
declaringType: typeof(CustomWebView),
defaultValue: default(string));
public string Uri
{
get { return (string)GetValue(UriProperty); }
set { SetValue(UriProperty, value); }
}
}
Then in ios make a renderer for the same and do something like this:
[assembly: ExportRenderer (typeof(CustomWebView), typeof(CustomWebViewRenderer))]
namespace DisplayPDF.iOS
{
public class CustomWebViewRenderer : ViewRenderer<CustomWebView, UIWebView>
{
protected override void OnElementChanged (ElementChangedEventArgs<CustomWebView> e)
{
base.OnElementChanged (e);
if (Control == null) {
SetNativeControl (new UIWebView ());
}
if (e.OldElement != null) {
// Cleanup
}
if (e.NewElement != null) {
var customWebView = Element as CustomWebView;
string fileName = Path.Combine (NSBundle.MainBundle.BundlePath, string.Format ("Content/{0}", WebUtility.UrlEncode (customWebView.Uri)));
Control.LoadRequest (new NSUrlRequest (new NSUrl (fileName, false)));
Control.ScalesPageToFit = true;
}
}
}
}
Then use the custom control like this:
<local:CustomWebView Uri="FooPath" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />
Where FooPath is the path for the doc file.
answered Nov 23 at 6:51
G.hakim
2,7411627
2,7411627
add a comment |
add a comment |
I have solution for my project, I try it:
If you only open file .docx on iOS, you could write code at Share Code of iOS:
Check device of user has setup app (Word, Excel, PP, etc...)
public static bool HasSetupAppDocument(string extension)
{
if (string.IsNullOrEmpty(extension))
return false;
// Device has setup app?
var result = UIApplication.SharedApplication.CanOpenUrl(NSUrl.FromString($"{extension}"));
return result;
}
(Ex: extension
is ms-word:
or ms-excel:
or ms-excel:
Reference: https://docs.microsoft.com/en-us/office/client-developer/integration/integrate-with-office-from-ios-applications#office-protocols)
Notes: Add source to Info.plist
:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>ms-word</string>
<string>ms-excel</string>
<string>ms-powerpoint</string>
</array>
At Class Dependencies, open file with
URL
:
Device.OpenUri(new Uri($"{convertExtension}{url}"));
Note: url
is link file share on Onedrive and Be sure that account Onedrive as same as account login Word
app (if you had set security).
If file has mode Read-only
, app Word
will open file with mode Read-only
.
add a comment |
I have solution for my project, I try it:
If you only open file .docx on iOS, you could write code at Share Code of iOS:
Check device of user has setup app (Word, Excel, PP, etc...)
public static bool HasSetupAppDocument(string extension)
{
if (string.IsNullOrEmpty(extension))
return false;
// Device has setup app?
var result = UIApplication.SharedApplication.CanOpenUrl(NSUrl.FromString($"{extension}"));
return result;
}
(Ex: extension
is ms-word:
or ms-excel:
or ms-excel:
Reference: https://docs.microsoft.com/en-us/office/client-developer/integration/integrate-with-office-from-ios-applications#office-protocols)
Notes: Add source to Info.plist
:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>ms-word</string>
<string>ms-excel</string>
<string>ms-powerpoint</string>
</array>
At Class Dependencies, open file with
URL
:
Device.OpenUri(new Uri($"{convertExtension}{url}"));
Note: url
is link file share on Onedrive and Be sure that account Onedrive as same as account login Word
app (if you had set security).
If file has mode Read-only
, app Word
will open file with mode Read-only
.
add a comment |
I have solution for my project, I try it:
If you only open file .docx on iOS, you could write code at Share Code of iOS:
Check device of user has setup app (Word, Excel, PP, etc...)
public static bool HasSetupAppDocument(string extension)
{
if (string.IsNullOrEmpty(extension))
return false;
// Device has setup app?
var result = UIApplication.SharedApplication.CanOpenUrl(NSUrl.FromString($"{extension}"));
return result;
}
(Ex: extension
is ms-word:
or ms-excel:
or ms-excel:
Reference: https://docs.microsoft.com/en-us/office/client-developer/integration/integrate-with-office-from-ios-applications#office-protocols)
Notes: Add source to Info.plist
:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>ms-word</string>
<string>ms-excel</string>
<string>ms-powerpoint</string>
</array>
At Class Dependencies, open file with
URL
:
Device.OpenUri(new Uri($"{convertExtension}{url}"));
Note: url
is link file share on Onedrive and Be sure that account Onedrive as same as account login Word
app (if you had set security).
If file has mode Read-only
, app Word
will open file with mode Read-only
.
I have solution for my project, I try it:
If you only open file .docx on iOS, you could write code at Share Code of iOS:
Check device of user has setup app (Word, Excel, PP, etc...)
public static bool HasSetupAppDocument(string extension)
{
if (string.IsNullOrEmpty(extension))
return false;
// Device has setup app?
var result = UIApplication.SharedApplication.CanOpenUrl(NSUrl.FromString($"{extension}"));
return result;
}
(Ex: extension
is ms-word:
or ms-excel:
or ms-excel:
Reference: https://docs.microsoft.com/en-us/office/client-developer/integration/integrate-with-office-from-ios-applications#office-protocols)
Notes: Add source to Info.plist
:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>ms-word</string>
<string>ms-excel</string>
<string>ms-powerpoint</string>
</array>
At Class Dependencies, open file with
URL
:
Device.OpenUri(new Uri($"{convertExtension}{url}"));
Note: url
is link file share on Onedrive and Be sure that account Onedrive as same as account login Word
app (if you had set security).
If file has mode Read-only
, app Word
will open file with mode Read-only
.
answered Nov 26 at 16:29
Huu Bao Nguyen
15112
15112
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53429843%2fhow-to-open-file-doc-use-word-app-on-xamarin-forms%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You need a dependency service for this its not a xamarin forms thing!
– G.hakim
Nov 22 at 12:05
I want write code on iOS. You can supply solution @G.hakim
– Huu Bao Nguyen
Nov 22 at 12:07
I guess this guide here has necessary information.
– G.hakim
Nov 22 at 12:43
I only want that view file .doc on external app ("Word" app itunes.apple.com/us/app/microsoft-word/id586447913?mt=8). May be your solution don't fit with me.
– Huu Bao Nguyen
Nov 22 at 15:25
I find a answer is same with your answer stackoverflow.com/questions/51494932/… But you don't want "edit" file, Do you only want "view" file .docx with Word app?when open it to your app.
– user10666363
Nov 22 at 16:04