C# 为什么我的代码在project中找不到路径?
我使用此选项合并2个pad文件:C# 为什么我的代码在project中找不到路径?,c#,asp.net,c#-4.0,itext,C#,Asp.net,C# 4.0,Itext,我使用此选项合并2个pad文件: public static void MergePages(string outputPdfPath, string[] lstFiles) { lstFiles = new string[2] { @"Downloads\Certificates\119.FDV-3686.pdf", @"Downloads\Certificates\119.FDV-3686.pdf" }; out
public static void MergePages(string outputPdfPath, string[] lstFiles)
{
lstFiles = new string[2] { @"Downloads\Certificates\119.FDV-3686.pdf",
@"Downloads\Certificates\119.FDV-3686.pdf" };
outputPdfPath = @"Downloads\Certificates\";
PdfReader reader = null;
Document sourceDocument = null;
PdfCopy pdfCopyProvider = null;
PdfImportedPage importedPage;
sourceDocument = new Document();
pdfCopyProvider = new PdfCopy(sourceDocument,
new System.IO.FileStream(outputPdfPath, System.IO.FileMode.Create));
sourceDocument.Open();
try
{
for (int f = 0; f < lstFiles.Length - 1; f++)
{
int pages = 1;
reader = new PdfReader(lstFiles[f]);
//Add pages of current file
for (int i = 1; i <= pages; i++)
{
importedPage = pdfCopyProvider.GetImportedPage(reader, i);
pdfCopyProvider.AddPage(importedPage);
}
reader.Close();
}
sourceDocument.Close();
}
catch (Exception ex)
{
throw ex;
}
}
publicstaticvoidmergepages(stringoutputpdfpath,string[]lstFiles)
{
lstFiles=新字符串[2]{@“Downloads\Certificates\119.FDV-3686.pdf”,
@“下载\证书\ 119.FDV-3686.pdf”};
outputPdfPath=@“下载\证书\”;
PdfReader reader=null;
Document sourceDocument=null;
PdfCopy pdfCopyProvider=null;
PDF导入页面导入页面;
sourceDocument=新文档();
pdfCopyProvider=新的PdfCopy(sourceDocument,
新的System.IO.FileStream(outputPdfPath,System.IO.FileMode.Create));
Open();
尝试
{
对于(int f=0;f
如果要将文件从解决方案文件夹复制到应用程序输出目录,可以将文件属性“复制到输出目录”设置为“始终复制”或“更新时复制”。有关此主题的更多讨论,请参阅
可以通过选择解决方案资源管理器下的文件来设置文件属性
(2) 另一个问题是您没有设置文件路径的根目录。我建议您使用以下样式表示文件路径:
var rootLocation = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase.ToString()).LocalPath);
var filePath1 = Path.Combine(rootLocation,@"Downloads\Certificates\filename1.pdf");
var filePath2 = Path.Combine(rootLocation,@"Downloads\Certificates\filename2.pdf");
..
(1) 一个问题可能是,您的设计时pdf文件在编译期间没有复制到应用程序输出目录。因此,它们在运行时不可用
如果要将文件从解决方案文件夹复制到应用程序输出目录,可以将文件属性“复制到输出目录”设置为“始终复制”或“更新时复制”。有关此主题的更多讨论,请参阅
可以通过选择解决方案资源管理器下的文件来设置文件属性
(2) 另一个问题是您没有设置文件路径的根目录。我建议您使用以下样式表示文件路径:
var rootLocation = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase.ToString()).LocalPath);
var filePath1 = Path.Combine(rootLocation,@"Downloads\Certificates\filename1.pdf");
var filePath2 = Path.Combine(rootLocation,@"Downloads\Certificates\filename2.pdf");
..
它是临时asp.net的目标files@CodingManiac我更改了我的答案,现在检查rootLocation解析..它是临时asp.net的目标files@CodingManiac我更改了我的答案,请立即查看。。