变量param值来自经典的asp调用.NET组件方法

时间:2013-02-21 08:13:10

标签: c# .net asp-classic

我使用PDFsharp项目将许多pdf文档合并到一个文件中,该文件非常流畅。 但我还需要从经典的ASP服务器页面调用此方法。

同样适用,但奇怪的是通过调用方法来处理param值。

C#定义:

public void MergeMultiplePDF(object[] files, string outFile)
{
  // note: get an array from vbscript, so files need to be a object array, not string array.

  // Open the output document
  PdfDocument outputDocument = new PdfDocument();

  // Iterate files
  foreach (string file in files)
  {
    // Open the document to import pages from it.
    PdfDocument inputDocument = PdfReader.Open(file, PdfDocumentOpenMode.Import);

    // Iterate pages
    int count = inputDocument.PageCount;
    for (int idx = 0; idx < count; idx++)
    {
      // Get the page from the external document...
      PdfSharp.Pdf.PdfPage page = inputDocument.Pages[idx];
      // ...and add it to the output document.
      outputDocument.AddPage(page);
    }
  }

  // Save the document...
  outputDocument.Save(outFile);
  outputDocument.Dispose();
}

来自经典ASP的电话:

Dim l_sPath : l_sPath = "D:\test\"
oPDF.MergeMultiplePDF Array(l_sPath & "sample1.pdf", l_sPath & "sample2.pdf", l_sPath & "sample3.pdf" ), l_sPath & "output.pdf"

工作正常,因为数组是一个对象VARIANT,我在.NET类中处理数组。

但是,如果我在经典ASP中有一个“动态”数组,我会得到通常的错误,即参数不正确,就像你在这里的很多帖子中找到的那样......

样品:

Dim myFiles(10)
For i = 0 To UBound(myFiles)
  myFiles(i) = "test" & i & ".pdf"
Next
oPDF.MergeMultiplePDF myFiles, l_sPath & "output.pdf"

这会导致参数错误。

我的解决方法:

oPDF.MergeMultiplePDF Split(Join(myFiles,","),","), l_sPath & "output.pdf"

然后它有效。

两者都是Array()类型的对象。

所以任何人都知道为什么处理不同?

2 个答案:

答案 0 :(得分:0)

在ASP中定义动态数组,如ReDim myFiles(max_count),其中max_count是一个数值会导致问题。 Dim myFiles(10)作为测试,例如Simon测试的工作。

@Simon,请将您的评论设为答案,以便我接受。

答案 1 :(得分:0)

您发布的代码应该像在VBScript中一样工作

VarType(Array(...)) = VarType(myFiles) = VarType(Split(...)) = 8204

8204 = 0x200C,VT_ARRAY | VT_VARIANT确实在.NET中转换为object[]

因此,实际代码与此处显示的示例不同。