asp.net 的图片相对路径?
1个回答
展开全部
给你个例子参考一下: 【前台】 #Code: <form id="form1" runat="server"> <div> <asp:fileupload ID="Fileupload1" runat="server"></asp:fileupload> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> </div> </form>#Code 【后台】 #Code protected void Button1_Click(object sender, EventArgs e) { if (Fileupload1.HasFile == true) { string name = Fileupload1.PostedFile.FileName; FileInfo info = new FileInfo(name); string aa = Server.MapPath("/images/" + info.Name); Fileupload1.SaveAs(aa); } else { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "aa", "javascript:alert('图片不为空!')", true); } } #Code Server.MapPath获取到的是相对路径!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询