顶一下,我用的是 If (FileUpload1.HasFile) Then Try Dim path As String = HttpContext.Current.Request.MapPath("~/upload/") Dim nowTime = Now Dim fileName = nowTime.ToString + User.Identity.Name.ToString + path + FileUpload1.FileName ---------------------------------------------------------------------- FileUpload1.SaveAs(path + fileName) ---------------------------------------------------------------------- Response.Write("上传成功!") Dim filePath As String = path + fileName Catch ex As Exception txtMsg.Text = ex.Message End Try End If 其中横线中间的这句必须换成 FileUpload1.SaveAs(path + FileUpload1.FileName)然后才能写出来上传成功,否则就提示错误!还有啊,即使上传成功了,我把 Dim filePath As String = path + fileName这一句的filePath 插入到数据库中, 出来的却是D:\..\网站的目录+\upload,这样的实际本地物理路径,咋给它在IIS中换成真实的www.xxx.com/.../upload 路径呢,高手帮帮忙吧~~
//new file name
string newFile = System.Guid.NewGuid().ToString() + ".jpg"//get the path
string path = Server.MapPath("~/") ;xx.PostedFile.SaveAs( path + newFile );//
<asp:Image runat="server" id='img1'/>//
img1.ImageUrl = "~/xxx.gif";
上面的.jpg太限定了,上传的可能是各种各样的格式,比如txt,rar等等,都要把他们自动转换名字,以免发生冲突,该怎么弄呢,还有这个方法System.Guid.NewGuid()是什么作用,能详细解释一下吗
有没有人能给出VB的代码,谢谢了~
{
strAc = strFile + "[下载后请删除括号重命名-上传时间-" + DateTime.Now.ToString("yy年MM月dd日hh时mm分ss秒") + "]"; //保证无同名的,并且保证数据安全。...//上传信息保存到数据库并保存原文件名和改写的文件路径string strPath = "..\\upload\\" + strAc;
fuAc.SaveAs(this.Server.MapPath(strPath));}前台读取到时候就直接读书上面2个存的信息,前者就是显示的名,后者就是连接的路径
Try
Dim path As String = HttpContext.Current.Request.MapPath("~/upload/")
Dim nowTime = Now
Dim fileName = nowTime.ToString + User.Identity.Name.ToString + path + FileUpload1.FileName
----------------------------------------------------------------------
FileUpload1.SaveAs(path + fileName)
----------------------------------------------------------------------
Response.Write("上传成功!")
Dim filePath As String = path + fileName Catch ex As Exception
txtMsg.Text = ex.Message
End Try
End If 其中横线中间的这句必须换成 FileUpload1.SaveAs(path + FileUpload1.FileName)然后才能写出来上传成功,否则就提示错误!还有啊,即使上传成功了,我把 Dim filePath As String = path + fileName这一句的filePath 插入到数据库中, 出来的却是D:\..\网站的目录+\upload,这样的实际本地物理路径,咋给它在IIS中换成真实的www.xxx.com/.../upload 路径呢,高手帮帮忙吧~~