62,244
社区成员




protected void BtnUpload_Click(object sender, EventArgs e)
{
if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.ContentLength > 0)
{
string ext = System.IO.Path.GetExtension(FileUpload1.PostedFile.FileName).ToLower();
if (ext != ".PDF" && ext != ".pdf")
{
//Common.ShowMessage.Show(Page, "error", "请选择PDF文件!");
return;
}
string filename = "tmp" + ext;
string path = "/pdftmp/" + filename;
HfPath.Value = path;
FileUpload1.PostedFile.SaveAs(Server.MapPath(path));
}
}
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button Text="上传" runat="server" ID="BtnUpload" OnClick="BtnUpload_Click"/>
<asp:Button Text="预览" runat="server" OnClientClick="return preview();"/>
<asp:HiddenField ID="HfPath" runat="server" />
</div>
</form>
<script>
function preview() {
var path = $('#<%=HfPath.ClientID%>').val();
window.open('Scripts/PdfJs/web/viewer.html?file=' + path, '_blank', 'height=480,width=640,top=' + (window.screen.height - 150) / 2 + ',left=' + (window.screen.width - 300) / 2 + ', toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
return false;
}
</script>
//从控件上传文件
public void fileUpload()
{
if (fuPhoto.PostedFile != null && fuPhoto.PostedFile.ContentLength > 0)
{
string ext = System.IO.Path.GetExtension(fuPhoto.PostedFile.FileName).ToLower();
if (ext != ".PDF" && ext != ".pdf")
{
Common.ShowMessage.Show(Page, "error", "请选择PDF文件!");
return;
}
string filename = "tmp" + ext;
string path = "./pdftmp/" + filename;
Label101.Text = fuPhoto.PostedFile.FileName;
fuPhoto.PostedFile.SaveAs(Server.MapPath(path));
Response.Write("<script language=javascript>window.open('web/viewer.html?file=../pdftmp/tmp.pdf','_blank','height=480,width=640,top='+(window.screen.height-150)/2 + ',left=' + (window.screen.width-300)/2 + ', toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')</script>");
//Response.Redirect("web/viewer.html?file=../pdftmp/tmp.pdf") ;
//Response.Write("<script>window.open(web/viewer.html?file=../pdftmp/tmp.pdf'',''_blank'')</script>");
//Server.Transfer("XXX.aspx");
}
else
{
//do some thing;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
fileUpload();
}
<asp:Button ID="Button1" runat="server" Text="预览" onclick="Button1_Click"
Width="45px" />
<asp:FileUpload ID="fuPhoto"
runat="server" ToolTip="选择文件" Width="264px" />