- Home
- Forum
- Xamarin.Forms
- open failed: ENOENT (No such file or directory) exception while creating pdf
open failed: ENOENT (No such file or directory) exception while creating pdf
Hi,
I am trying to create a pdf from my XAML, and followed the exact same instructions in the following link:
https://www.syncfusion.com/kb/9174/how-to-create-a-pdf-file-in-xamarin
but problem is that it doesn't create anything,! tried to debug the code and realized that in SaveAndroid class on the line 'FileOutputStream outs = new FileOutputStream(file);' it throws an exception, and here is the message: "/storage/emulated/0/Syncfusion/Output.pdf: open failed: ENOENT (No such file or directory)"
so, can you please help me with this issue?
I also had the same issue when I tried to run this sample:
Thanks in advance
SIGN IN To post a reply.
7 Replies
KC
Karthikeyan Chandrasekar
Syncfusion Team
November 19, 2018 12:24 PM UTC
Hi Reihaneh,
Thank you for contacting Syncfusion support.
The ENOENT (No such file or directory) error may occur in application, If the application do not have storage permission. We suggest you to ensure whether the application has storage permission to read and write file in storage location. We have modified sample to provide storage permission at run time. Please find the sample below for your reference.
Kindly refer below Xamarin link to provide permission for android application.
Please let us know if you need further assistance in this.
Regards,
Karthikeyan
RK
Reihaneh Khaksaran
November 19, 2018 04:19 PM UTC
Hi,
Oh, you're right, sorry, problem solved, thank you so much
oh and one more question, where is the file saved? I searched my all the directories on my phone but couldn't find the generated pdf!! I'm just able to open it from whithin the application!
Best Regards,
Reihaneh
KC
Karthikeyan Chandrasekar
Syncfusion Team
November 20, 2018 10:17 AM UTC
Hi Reihaneh,
The PDF file is saved in android platform using SaveTextAsync method from SaveAndroid class and it is included in Android project. In the SaveTextAsync method we are creating folder name with Syncfusion and inside the folder the PDF file is created. You can find the output PDF file “/storage/emulated/0/Syncfusion/Output.pdf” in this location.
Please let us know if you need further assistance on this.
Regards,
Karthikeyan
CC
Christian Campos
October 25, 2021 05:04 PM UTC
The sample works because it uses a old Xamarin Forms Version, using XF 5, the exception is throwed.
Another comment, the exception is throwed using Android target version to 11, if you set it to 10 or 9, it works fine.
GK
Gowthamraj Kumar
Syncfusion Team
October 26, 2021 09:07 AM UTC
Hi Christian,
Thank you for contacting Syncfusion support.
We have created a sample to write the PDF document in Android 11 and attached it for your reference. Kindly try this sample on your end and let us know whether it works or not.
In this sample we have modified the following
- Enabled the androidLegacyExtranalStorage in the AndroidManifest.xml file.
|
<application android:label=" PDFXamarinSample.Android" android:requestLegacyExternalStorage="true"> |
- User permission for read, write external storage.
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE">
</uses-permission>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> |
- Replaced the following code to get the external storage download folder in the SaveAndroid.cs file.
|
if (Android.OS.Environment.IsExternalStorageEmulated)
{
root = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads).AbsolutePath;
} |
Sample link: https://www.syncfusion.com/downloads/support/forum/140979/ze/PDFXamarinSample11-695493062
If still you are facing an same issue, kindly please share the modified sample to check the issue on our end. So, that it will be helpful for us to analyze and assist you further on this.
Regards,
Gowthamraj K
CH
Charlie
November 8, 2022 05:29 PM UTC
This article needs updated to include
Karthikeyan and
Gowthamraj's fixes. It does not work for Xamarin.Forms 5.0.0.2196 and Android 11 without their suggestions. FileProvider, though mentioned in the article, also isn't shown in the code samples.
IJ
Irfana Jaffer Sadhik
Syncfusion Team
November 10, 2022 12:50 PM UTC
We will consider your request to update the documentation. We will let you know once the KB documentation got published with the requested changes.
SIGN IN To post a reply.
- 7 Replies
- 6 Participants
-
RK Reihaneh Khaksaran
- Nov 16, 2018 04:56 PM UTC
- Nov 10, 2022 12:50 PM UTC