We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

The access to the path "C:\...." is denied when converting drag-and-droped xml and xsl into pdf

I’m making a UWP app with Visual Studio 2022. A user can convert .xml and .xsl into a .pdf by drag-and-dropping them into an app.

The problem is that Aspose can’t read xml neither xsl. They try to access its path obtained from drag-and-drop.

MainPage.xaml.cs

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

namespace XML2PDF
{
    /// <summary>
    /// made from a blank page
    /// </summary>
    public sealed partial class MainPage : Page
    {
        string xmlPath;
        string xslPath;
        public MainPage()
        {
            this.InitializeComponent();
            xmlPath = "";
            xslPath = "";
        }

        private void BackgroundGrid_DragEnter(object sender, DragEventArgs e)
        {
            e.AcceptedOperation = Windows.ApplicationModel.DataTransfer.DataPackageOperation.Move;
        }

        private async void BackgroundGrid_Drop(object sender, DragEventArgs e)
        {
            if (e.DataView.Contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.StorageItems))
            {
                var items = await e.DataView.GetStorageItemsAsync();
                var filePaths = items.Select(x => x.Path).ToList();
                foreach (var p in filePaths)
                {
                    if (p.EndsWith(".xml"))
                    {
                        xmlPath = p;
                        continue;
                    }
                    if (p.EndsWith(".xsl"))
                    {
                        xslPath = p;
                        continue;
                    }
                }
            }
            // TODO: check if xmlPath and xslPath aren't empty
            this.ConvertXML2PDF(xmlPath, xslPath);
        }

        private async void ConvertXML2PDF(string xmlPath, string xslPath)
        {
            Aspose.Pdf.Document pdf = new Aspose.Pdf.Document();
            string pdfPath = xmlPath.Replace(".xml", "pdf");
            try
            {
                pdf.BindXml(xmlPath, xslPath);
                // System.UnauthorizedAccessException: 'Access to the path 'C:\Users\path\to\filename.xsl' is denied.'
            }
            catch (System.Exception e)
            {
                throw e;
            }
        }
    }
}

MainPage.xaml

<Page
    x:Class="XML2PDF.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:XML2PDF"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid x:Name="BackgroundGrid" Background="Transparent" AllowDrop="True" DragEnter="BackgroundGrid_DragEnter" Drop="BackgroundGrid_Drop" />
</Page>

Package.appmanifest

<?xml version="1.0" encoding="utf-8"?>

<Package
  xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
  xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
  xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
  IgnorableNamespaces="uap mp">

  ...

  <Capabilities>
    <Capability Name="internetClient" />
  </Capabilities>
</Package>

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

  Issue ID(s): PDFNET-53514

You can obtain Paid Support services if you need support on a priority basis, along with the direct access to our Paid Support management team.

1 Like

Thanks. I’m happy to pay as long as it is fixed.