c# - C# 控制台应用程序需要有关主要参数错误的帮助
问题描述
我有以下 c# Console 应用程序,我将在 ssis 中运行它,但我使用了几个 PDF 操作库。所以我要在传递文件路径时从我的 ssis 包中调用一个 exe。
但是尝试通过exe运行时出现以下错误。
未处理的异常:System.IndexOutOfRangeException:索引超出了数组的范围。在 ConsoleApp.program.Main(String[] args) 第 87 行
但是如果我在调试中运行它工作正常。一旦我通过exe让它自己工作,我想将文件路径作为参数传递给ssis。
见下面的c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using org.apache.pdfbox.pdmodel;
using org.apache.pdfbox.util;
using System.IO;
namespace PDF_Read_ConsoleApp
{
class Program
{
public static void FilePath(string path)
{
//Console.WriteLine("Please enter full pdf path \n\n ");
//path = Console.ReadLine();
string fp;
fp = @path;
string[] files = Directory.GetFiles(path, "*.pdf");
foreach (string s in files)
{
string txtOutput = s.Replace(".pdf", ".txt");
if (File.Exists(txtOutput))
{
File.Delete(txtOutput);
}
string output;
PDDocument doc = null;
try
{
doc = PDDocument.load(s);
PDFTextStripper stripper = new PDFTextStripper();
stripper.getText(doc);
output = stripper.getText(doc);
StreamWriter NewFile;
NewFile = new StreamWriter(txtOutput);
//NewFile.Write(output.ToString());
NewFile.Write(output.ToString());
NewFile.Close();
}
finally
{
//if (doc != null)
//{
doc.close();
// Console.WriteLine("\n\n File saveed - ({0} ", txtOutput);
//}
}
}
}
static void Main(string[] args)
{
args[0] = @"C:\SSIS_Packages\PDF_Import\PDF_Import\PO_pdfs"; //// TESTING FILE PATH1
FilePath(args[0]);
}
}
}
亲切的问候
抢
解决方案
I have managed to get it working, I need to enter an argument within the debug screen, see information in URL below
Console app arguments, how arguments are passed to Main method
THank you for everyone's comments
推荐阅读
- css - h1定位问题
- c++ - 对整个数组进行冒泡排序
- php - if..else 嵌套在 oci 和 php 的 while 循环中,但 if...else 没有被调用
- openlayers - 有没有办法在 openlayers 5 中强制重新加载/刷新地图?
- python - Entrez (biopython):如何将术语搜索限制在特定期刊?(考研)
- android - 由于权限政策,我无法发布我的应用
- twitter-bootstrap - Bootstrap 4 - col-sm-12 的 col 没有响应
- java - Thymeleaf 使用 th:each 动态创建表单
- java - 从 csv 文件导入 Excel 进行转换
- javascript - HTML onClick 属性不调用函数