上传文件

aspx

<div class="tab-content" style="display:none">
             
             <dl>
                <dt>资料名称</dt>
                <dd>
                    <asp:TextBox ID="txtBname" runat="server"  CssClass="input normal" datatype="*1-100" sucmsg=" "></asp:TextBox>
                    <span class="Validform_checktip">*分类中文名称,100字符内</span></dd>
            </dl>
            <dl>
                <dt>资料</dt>
                <dd>
                    <asp:Image ImageUrl="../../../css/noneimg.jpg" ID="img2" runat="server" Width="150px" Height="150px" />
                        <asp:FileUpload runat="server" ID="fupImage" />
                <%-- <input type="button" value="上传" id="Button1" runat="server" onserverclick="btnSubmit_ServerClick" />--%>
                  <%--  <asp:Image ID="showImg" runat="server" ImageUrl="../../../css/noneimg.jpg" Style="max-height: 80px;" />
                    <asp:TextBox ID="txtlogoUrl" runat="server" CssClass="input normal upload-path" datatype="*1-800" sucmsg=" " Text="" nullmsg=" "/>
                    <div class="upload-box upload-img"></div>--%>
                    <asp:Label ID="tip" runat="server" Text=""></asp:Label>
                </dd>
            </dl>
        <div class="page-footer">
            <div class="btn-list">
                <asp:Button ID="btnSubmit" runat="server" Text="提交保存" CssClass="btns" OnClick="btnsSubmit_Click" />
                <input name="btnReturn" type="button" value="返回上一页" class="btn yellow" onclick="javascript: history.back(-1);" />
            </div>
            <div class="clear"></div>
        </div>
        </div>

aspx.cs 

protected void btnsSubmit_Click(object sender, EventArgs e)
{
TeenySoft.CacheLoginUser.LoginUser loginuser = GetAdminInfo;
if (fupImage.HasFile)
{
string data = DateTime.Now.ToShortDateString();
Regex regex = new Regex(@".(?i:jpg|jpeg|gif|png|docx|xlsx|zip|rar|txt)$");
if (regex.IsMatch(Path.GetExtension(fupImage.FileName)))
{
string path = AppDomain.CurrentDomain.BaseDirectory + "uploads";
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
string filePath = fupImage.FileName;  //此处需要处理同名文件
fupImage.SaveAs(Path.Combine(path, filePath));
img2.ImageUrl = "/uploads/" + filePath;
string strSql = String.Format("insert into {0}.dbo.wx_shop_businessfile([filename],updatedate,filepath) values('{1}','{2}','{3}')",
loginuser.DBName, this.txtBname.Text, data, img2.ImageUrl);
TeenySoft.Query.DBCommon.ExecuteScalar(loginuser.ConnectionStr, strSql, CommandType.Text, null);
JscriptMsg("保存完成继续上传!", "uploadbusiness.aspx", "Success");
}
else
{
this.tip.Text = "请选择正确的文件格式!";
}
}
else
{
this.tip.Text = "请选择文件!";
}
}

 

posted @ 2016-07-08 10:32  小A爱吧  阅读(145)  评论(0编辑  收藏  举报