这是我第一次在 ASP.NET 中做任何事情,所以对于一个有经验的 ASP.NET 开发人员来说,我可能正在做一些非常愚蠢的事情。
情况是这样的:我有很多文件只是命名为 GUID 而没有文件扩展名。有时我想在网络浏览器中呈现这些。如果我手动重命名带有.pdf
文件扩展名的文件,这一切都很好。我正在尝试在 ASP.NET 中编写一个脚本来复制文件以在请求时添加扩展名。这是我的代码:
<script runat="server">
dim guid = HttpContext.Current.Request.QueryString("file")
dim path = HttpContext.Current.Request.PhysicalApplicationPath
dim origin = path + guid
dim destination = origin + ".pdf"
System.IO.File.Copy(origin, destination)
</script>
<html>
<head>
<script src="jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var htmldata = "<embed src='http://myurl.com/<%=guid%>.pdf' style='width:100%; height:100%;'>";
document.getElementById('pdf').innerHTML = htmldata;
});
</script>
</head>
<body>
<span id="pdf"></span>
</body>
</html>
这会引发以下错误:
Description: An error occurred during the compilation of a resource required to
service this request. Please review the following specific error details and
modify your source code appropriately.
Compiler Error Message: BC30188: Declaration expected.
Source Error:
Line 6: dim destination = origin + ".pdf"
Line 7:
Line 8: System.IO.File.Copy(origin, destination)
Line 9: </script>
Line 10: <html>
C:\path\to\web\root\default.aspx(8) Line: 8
Show Detailed Compiler Output:
c:\windows\system32\inetsrv> REALLY LONG LINE THAT I'LL INCLUDE IF NEEDED
Microsoft (R) Visual Basic Compiler version 10.0.30319.233
Copyright (c) Microsoft Corporation. All rights reserved.
C:\path\to\web\root\default.aspx(8) : error BC30188: Declaration expected.
System.IO.File.Copy(origin, destination)
~~~~~~