如何在xamarin android中使用c#将字节数组转换为pdf?

如何在xamarin android中使用c#将字节数组转换为pdf?,c#,xamarin,xamarin.android,C#,Xamarin,Xamarin.android,我正在尝试使用c.将xamarin android应用程序中的字节转换为pdf。 其中字节来自webservice。我使用simplewebservice(asmx)带来数据 appLoginService = new EgrasAndroid.AppLoginService(); byte[] grnbytedata= appLoginService.GetGRNPdf(UserId.ToString(), GRN.ToString()); string directory = Path

我正在尝试使用
c.
将xamarin android应用程序中的字节转换为pdf。 其中字节来自
webservice
。我使用simple
webservice(asmx)
带来数据

 appLoginService = new EgrasAndroid.AppLoginService();
 byte[] grnbytedata= appLoginService.GetGRNPdf(UserId.ToString(), GRN.ToString());
 string directory = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, Android.OS.Environment.DirectoryDownloads);
 string file = Path.Combine(directory, "temp.pdf");
 System.IO.File.WriteAllBytes(file, grnbytedata);
我已经搜索了许多解决方案,但它们大多适用于web应用程序或java应用程序

它没有显示任何错误。我在emulator上运行这个,但下载文件夹中显示了一个文件。当它采用路径“/storage/sdcard/Download”下载文件时


有200mb的空白,我在emulator中为SD卡使用了。

检查您的路径。从棉花糖访问文件的方式有所改变。下面的代码应该可以做到这一点

      if (Int32.Parse(Android.OS.Build.VERSION.Release.Substring(0, 1)) > 5)
            {
                documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            }
            else
            { 
                documentsPath = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, Android.OS.Environment.DirectoryDownloads); 
            }
问题是: Emulator本身没有pdf阅读器。所以它无法读取pdf文件。 在emulator中,您必须下载PDF阅读器。否则,它在实际设备中工作正常

如果设备或emulator中没有外部存储,则我们可以使用以下方法进行内部存储:

  var directory = global::Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
  directory= Path.Combine(directory ,Android.OS.Environment.DirectoryDownloads);
  string file = Path.Combine(directory.ToString(), "temp.pdf");
  System.IO.File.WriteAllBytes(file, grnbytedata);

写入字节有什么问题?有错误吗?你试过调试它吗?
grnbytedata
是否包含任何值?有点不清楚你在问什么。请添加更多详细信息返回数据井。。WriteAllbytes没有错误,但下载后不会显示任何文件。。我无法在emulator上的任何位置看到该文件。您可能没有写入数据的权限-请检查它们是否处于打开状态@DanyDaKur是的,我已经检查了android中的读写外部存储,谢谢,但你说的是java代码。在c#中没有比Environment.GetFolderPath更好的了。路径正常,但问题是emulator中并没有pdf阅读器。