0

I'm getting the above error when trying to print a file with my Xamarin app through call to a web service method. When same method is called from browser it prints without problem. Write and read permissions for external storage are granted. The file I want to print is located in a shared network folder. What could be the reason that folder access is denied only for the app?

That's the part of the code where filepath is used:

public static string SubstituteFileContent(string filePath, string substituteValues)
        {
            var rdr = new StreamReader(filePath);
            var fileContent = rdr.ReadToEnd();
            //textBoxSource.Text = fileContent;
            var index = fileContent.IndexOf("^XA");
            fileContent = fileContent.Remove(0, index);
            var start = fileContent.IndexOf("^DFE");
            var end = fileContent.IndexOf(".ZPL^");
            fileContent = fileContent.Remove(start, end - start + 4);

            rdr.Close();

            var substitutedContent = SubstituteFields(fileContent, substituteValues);
            return substitutedContent;
        }
bigb055
  • 198
  • 3
  • 14
  • please post the relevant code – Jason Jan 30 '18 at 17:41
  • It may be that you still don't have read/write permission because Depending on the version of Android you have to specifically prompt the user for it to be allowed. [Here's](https://stackoverflow.com/questions/46911486/xamarin-system-unauthorizedaccessexception-access-to-the-path-is-denied/46933816#46933816) an example of that. – Nick Peppers Jan 30 '18 at 17:52
  • `a shared network folder` ? Are you uploading it from your Android to the web server? Trying to access a shared network folder (SMB-based?) from Android? etc.. ? – SushiHangover Jan 30 '18 at 18:52
  • @Nick this happens on API 19 – bigb055 Jan 31 '18 at 08:13
  • @SushiHangover I'm trying to read a file from a shared folder on the server. No idea if SMB-based or not... – bigb055 Jan 31 '18 at 08:39
  • So, you can't access the path which is on your server from your app? I don't think it is your problem. – Robbit Jan 31 '18 at 09:24
  • Yeah, if you're not copying the file to your device to then print it sounds like you don't have permission from the network folder – Nick Peppers Jan 31 '18 at 13:30
  • @Nick, but I gave full control to all users under folder sharing options. Moreover, when I copy the files on same machine where android emulator is running they print without issues. – bigb055 Jan 31 '18 at 14:33

1 Answers1

-1

Ok, solved it myself. I had to explicitly share the network folder with "Everyone" under Share settings.

bigb055
  • 198
  • 3
  • 14