本地path E:\VSS 
文件名 a.jpg
服务器ip:192.168.4.111
服务器path D:\My Documents

解决方案 »

  1.   


    //上传照片到image文件夹
            protected void Button1_Click(object sender, EventArgs e)
            {
                string filename = FileUpload1.FileName;//文件名(文件类型,如hello.gif)
                string fileType=filename.Substring(filename.LastIndexOf(".")+1);//文件类型
                string filePath = Server.MapPath(filename);//文件的物理地址
                string serverPath = "";//存储服务器物理地址            double size = FileUpload1.PostedFile.ContentLength / 1024;            if (size > 60)
                {
                    Label1.Text = "图片大小不超过60kb";
                }
                else
                {
                    if (fileType == "bmp" || fileType == "jpg" || fileType == "gif")
                    {
                        string newName = DateTime.Now.ToFileTime() + "." + fileType;
                        serverPath = Server.MapPath("192.168.4.111/My Documents/") + newName;
                        FileUpload1.SaveAs(serverPath);//保存文件
                        Label1.Text = "上传成功!";
                        Image1.Visible = true;
                        Image1.ImageUrl = "image/" + newName;
                    }
                    else
                    {
                        Label1.Text = "请选择正确的图片类型";
                    }
                }
            }试试,我也没试过,这是我将以前的拿来改的,因为没有传到服务器上过
      

  2.   

    string serverPath = Server.MapPath("~");//绝对路径
                string serverfacePath = "/Accessories/" + CompanyId + "/" + StringHelper.GetDate() + "/";
                DirectoryInfo companyDirectory = new DirectoryInfo(serverPath + serverfacePath);            if (!companyDirectory.Exists)
                {
                    companyDirectory.Create();
                }            if (fileAddPic.HasFile)
                {
                    //FileExtension[] fe = { FileExtension.GIF, FileExtension.JPG, FileExtension.PNG };                
                    string fileContentType = fileAddPic.PostedFile.ContentType;
                    if (fileContentType.StartsWith("image"))
                    {
                        string oldImg = imgPhoto.ImageUrl;
                        if (oldImg.Length > 2)
                        {
                            string delImg = serverPath + oldImg.Substring(2);
                            if (File.Exists(delImg))
                            {
                                File.Delete(delImg);
                            }
                        }                    string fileExtension = System.IO.Path.GetExtension(fileAddPic.FileName);//扩展名
                        string fileTrueName = StringHelper.GetTime() + StringHelper.GetRandomNumberString(5) + fileExtension;
                        fileAddPic.SaveAs(serverPath + serverfacePath + fileTrueName);
                        bsProducts.UpdateProductPic(CompanyId, proId, serverfacePath + fileTrueName);
                     }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this.upAddPic, this.GetType(), "error", "alert('只能上传图片文件!');", true);
                        return;
                    }
                }