yog*_*ate 2 .net c# exception pdf-writer
尝试使用以下代码编写PDF文档:
document = new Document();
PdfWriter writer = null; ;
try
{
writer = PdfWriter.GetInstance(document, new FileStream(@"E:\mergFiles", FileMode.Create));
}
catch (Exception xc)
{ }
Run Code Online (Sandbox Code Playgroud)
我得到一个例外:
{System.UnauthorizedAccessException: Access to the path 'E:\mergFiles' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode)
at PDFLibrary.PDFManager.MergeDocs()}
Run Code Online (Sandbox Code Playgroud)
我有权访问这个文件夹.
goggled,发现这可能有所帮助,File.SetAttributes(@"E:\mergFiles", FileAttributes.Normal);但我仍然得到相同的例外.
好吧,你不能将文件夹的名称传递给FileStream.它必须是包含路径的文件名(编辑:当然,如果使用相对文件名,它实际上不必包含路径).
如果要创建文件夹,请使用Directory.CreateDirectory.要在该文件夹中创建文件,请使用以下内容:
string fullName = Path.Combine(pathName, fileName);
writer = PdfWriter.GetInstance(document, new FileStream(fullName, FileMode.Create));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15816 次 |
| 最近记录: |