[英]Variant param values from classic asp calling .NET component method
I use the PDFsharp project to merge many pdf documents into one file which works perfectly and smooth. 我使用PDFsharp项目将许多pdf文档合并到一个文件中,该文件可以完美流畅地工作。 But I also need to call this method from classic ASP server pages.
但是我还需要从经典的ASP服务器页面调用此方法。
Works as well, but the strange thing is handling the param values by calling the method. 也可以,但是奇怪的是通过调用方法来处理参数值。
C# definition: 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();
}
Call from classic ASP: 来自经典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"
Works fine, as array is a object VARIANT and I handle the array inside the .NET class. 效果很好,因为array是一个对象VARIANT,我在.NET类中处理该数组。
But if I have a "dynamic" array in classic ASP I get the usual error that the argument is not correct like you can find in many posts here... 但是,如果我在经典ASP中有一个“动态”数组,则会遇到通常的错误,即参数不正确,就像您可以在此处的许多文章中找到的那样...
Sample: 样品:
Dim myFiles(10)
For i = 0 To UBound(myFiles)
myFiles(i) = "test" & i & ".pdf"
Next
oPDF.MergeMultiplePDF myFiles, l_sPath & "output.pdf"
This run into an argument error. 这遇到参数错误。
My workaround: 我的解决方法:
oPDF.MergeMultiplePDF Split(Join(myFiles,","),","), l_sPath & "output.pdf"
Then it works. 然后就可以了。
Both are objects of type Array(). 两者都是Array()类型的对象。
So anyone has a clue why this is handled different? 因此,有人知道为什么处理不同吗?
Defining a dynamic array in ASP like ReDim myFiles(max_count)
where max_count is a numeric value causes the problem. 在ASP中定义一个动态数组,例如
ReDim myFiles(max_count)
,其中max_count是一个数值会导致此问题。 Dim myFiles(10) as test for example work like Simon tested as well. 例如,将昏暗的myFiles(10)作为测试工作,例如Simon也进行了测试。
@Simon, set your comments as an answer please so I can accept it. @Simon,请将您的评论作为答案,以便我接受。
The code you post should work as in VBScript 您发布的代码应在VBScript中正常工作
VarType(Array(...)) = VarType(myFiles) = VarType(Split(...)) = 8204
8204 = 0x200C, which is VT_ARRAY | 8204 = 0x200C,即VT_ARRAY | VT_VARIANT which translate indeed to
object[]
in .NET VT_VARIANT确实转换为.NET中的
object[]
So, the actual code is different than the sample shown here. 因此,实际代码与此处显示的示例不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.