62,242
社区成员




this.fuldDoc.Style.Add("display", "none");
this.fuldDoc.Attributes.Add("onchange", "document.getElementById(\"txtDoc\").value=this.value");
此段代码为前台页面显示的内容
<td valign="top">
<div align="right">
行程文档:</div>
</td>
<td colspan="3">
<div align="left" style="color: #FF0000;">
<asp:TextBox ID="txtDoc" runat="server" ReadOnly="true" Width="437px" CssClass="txtarea"></asp:TextBox>
<asp:FileUpload ID="fuldDoc" runat="server" Height="20px" />
<input type="button" id="btnBrowse" value="浏览..." onclick="javascript:document.getElementById('fuldDoc').click();" />
<asp:Button ID="btnUploadDoc" runat="server" Text="上传" OnClick="btnUploadDoc_Click" />
<asp:Label ID="lblTip" runat="server" Text=""></asp:Label>
</div>
</td>
此段代码为上传按钮单击事件代码
protected void btnUploadDoc_Click(object sender, EventArgs e)
{
try
{
if (this.fuldDoc.HasFile)
{
string fileName = this.fuldDoc.FileName; //获取文件的名称
int index = fileName.LastIndexOf('.'); //获取文件后缀名的.的位置
string fileType = fileName.Substring(index).ToLower(); //获取文件扩展名
if (fileType.ToLower().Equals(".doc") || fileType.ToLower().Equals(".docx"))
{
string fileNewName = System.DateTime.Now.ToString("yyyyMMddHHmmss") + fileType; //重新命名文件名称
string filePath = Server.MapPath("/upload/file/" + System.DateTime.Now.ToString("yyyy-MM-dd") + "/");
if (!Directory.Exists(filePath))
Directory.CreateDirectory(filePath); //创建文件夹
string fileUrl = filePath + fileNewName;
this.fuldDoc.SaveAs(fileUrl);
this.lblTip.Text = "上传成功";
this.txtDoc.Text = BasicPage.BecomeVirtualPath(fileUrl);//将物理路径转换为虚拟路径
}
else
this.lblTip.Text = "格式不正确,上传的文件必须是doc或docx格式";
}
else
this.lblTip.Text = "请选择上传的文件";
}
catch
{
this.lblTip.Text = "上传失败,请联系管理员";
}
}
可有看出什么不对?[/quote]
上传代码不用看,你是浏览器不兼容的问题
我觉得可能有问题的地方在
javascript:document.getElementById('fuldDoc').click()
fuldDoc 这个ID是服务器控件ID 不是客户端控件ID,可能没找到ID,你需要这样
javascript:document.getElementById('<%=fuldDoc.ClentID%>').click()
纯手打 可能有错
你所谓的这种问题每个人都遇到,只是和你一样而已,浏览器不兼容[/quote]
也不行,还是一样的问题
this.fuldDoc.Style.Add("display", "none");
this.fuldDoc.Attributes.Add("onchange", "document.getElementById(\"txtDoc\").value=this.value");
此段代码为前台页面显示的内容
<td valign="top">
<div align="right">
行程文档:</div>
</td>
<td colspan="3">
<div align="left" style="color: #FF0000;">
<asp:TextBox ID="txtDoc" runat="server" ReadOnly="true" Width="437px" CssClass="txtarea"></asp:TextBox>
<asp:FileUpload ID="fuldDoc" runat="server" Height="20px" />
<input type="button" id="btnBrowse" value="浏览..." onclick="javascript:document.getElementById('fuldDoc').click();" />
<asp:Button ID="btnUploadDoc" runat="server" Text="上传" OnClick="btnUploadDoc_Click" />
<asp:Label ID="lblTip" runat="server" Text=""></asp:Label>
</div>
</td>
此段代码为上传按钮单击事件代码
protected void btnUploadDoc_Click(object sender, EventArgs e)
{
try
{
if (this.fuldDoc.HasFile)
{
string fileName = this.fuldDoc.FileName; //获取文件的名称
int index = fileName.LastIndexOf('.'); //获取文件后缀名的.的位置
string fileType = fileName.Substring(index).ToLower(); //获取文件扩展名
if (fileType.ToLower().Equals(".doc") || fileType.ToLower().Equals(".docx"))
{
string fileNewName = System.DateTime.Now.ToString("yyyyMMddHHmmss") + fileType; //重新命名文件名称
string filePath = Server.MapPath("/upload/file/" + System.DateTime.Now.ToString("yyyy-MM-dd") + "/");
if (!Directory.Exists(filePath))
Directory.CreateDirectory(filePath); //创建文件夹
string fileUrl = filePath + fileNewName;
this.fuldDoc.SaveAs(fileUrl);
this.lblTip.Text = "上传成功";
this.txtDoc.Text = BasicPage.BecomeVirtualPath(fileUrl);//将物理路径转换为虚拟路径
}
else
this.lblTip.Text = "格式不正确,上传的文件必须是doc或docx格式";
}
else
this.lblTip.Text = "请选择上传的文件";
}
catch
{
this.lblTip.Text = "上传失败,请联系管理员";
}
}
可有看出什么不对?[/quote]
上传代码不用看,你是浏览器不兼容的问题
我觉得可能有问题的地方在
javascript:document.getElementById('fuldDoc').click()
fuldDoc 这个ID是服务器控件ID 不是客户端控件ID,可能没找到ID,你需要这样
javascript:document.getElementById('<%=fuldDoc.ClentID%>').click()
纯手打 可能有错
你所谓的这种问题每个人都遇到,只是和你一样而已,浏览器不兼容
this.fuldDoc.Style.Add("display", "none");
this.fuldDoc.Attributes.Add("onchange", "document.getElementById(\"txtDoc\").value=this.value");
此段代码为前台页面显示的内容
<td valign="top">
<div align="right">
行程文档:</div>
</td>
<td colspan="3">
<div align="left" style="color: #FF0000;">
<asp:TextBox ID="txtDoc" runat="server" ReadOnly="true" Width="437px" CssClass="txtarea"></asp:TextBox>
<asp:FileUpload ID="fuldDoc" runat="server" Height="20px" />
<input type="button" id="btnBrowse" value="浏览..." onclick="javascript:document.getElementById('fuldDoc').click();" />
<asp:Button ID="btnUploadDoc" runat="server" Text="上传" OnClick="btnUploadDoc_Click" />
<asp:Label ID="lblTip" runat="server" Text=""></asp:Label>
</div>
</td>
此段代码为上传按钮单击事件代码
protected void btnUploadDoc_Click(object sender, EventArgs e)
{
try
{
if (this.fuldDoc.HasFile)
{
string fileName = this.fuldDoc.FileName; //获取文件的名称
int index = fileName.LastIndexOf('.'); //获取文件后缀名的.的位置
string fileType = fileName.Substring(index).ToLower(); //获取文件扩展名
if (fileType.ToLower().Equals(".doc") || fileType.ToLower().Equals(".docx"))
{
string fileNewName = System.DateTime.Now.ToString("yyyyMMddHHmmss") + fileType; //重新命名文件名称
string filePath = Server.MapPath("/upload/file/" + System.DateTime.Now.ToString("yyyy-MM-dd") + "/");
if (!Directory.Exists(filePath))
Directory.CreateDirectory(filePath); //创建文件夹
string fileUrl = filePath + fileNewName;
this.fuldDoc.SaveAs(fileUrl);
this.lblTip.Text = "上传成功";
this.txtDoc.Text = BasicPage.BecomeVirtualPath(fileUrl);//将物理路径转换为虚拟路径
}
else
this.lblTip.Text = "格式不正确,上传的文件必须是doc或docx格式";
}
else
this.lblTip.Text = "请选择上传的文件";
}
catch
{
this.lblTip.Text = "上传失败,请联系管理员";
}
}
可有看出什么不对?