要求
1.将图片上传到指定的文件夹下
2.给图片重新命名,截取图片中的图片名存到数据库
3.代码尽量详细点有注释最好

解决方案 »

  1.   

    winform 不叫上传 叫复制(反正都在本地)把原先的图片复制到相应的路径下
      

  2.   


    那就要用到TCP  UDP 等协议传文件了
      

  3.   

    使用BinaryStream
    Ftp上传的话,网上有现成的封装好的类可使用,搜一下吧
      

  4.   

    openfiledialog
    file.move
    上传使用webclient
      

  5.   


            ///<summary>
            /// WebClient上传文件至服务器 
            ///</summary>
            ///<param name="localFilePath">文件名,全路径格式</param>
            ///<param name="serverFolder">服务器文件夹路径</param>
            ///<param name="reName">是否需要修改文件名,这里默认是日期格式</param>
            ///<returns></returns>
            public static bool UploadFile(string localFilePath, string serverFolder,bool reName) 
            { 
                string fileNameExt, newFileName, uriString; 
                if (reName) 
                { 
                    fileNameExt = localFilePath.Substring(localFilePath.LastIndexOf(".") +1); 
                    newFileName = DateTime.Now.ToString("yyMMddhhmmss.") + fileNameExt; 
                }
                else
                { 
                    newFileName = localFilePath.Substring(localFilePath.LastIndexOf("\\")+1); 
                }            if (!serverFolder.EndsWith("/") &&!serverFolder.EndsWith("\\")) 
                { 
                    serverFolder = serverFolder +"/"; 
                }            uriString = serverFolder + newFileName;   //服务器保存路径
                /**//**//**//// 创建WebClient实例
                WebClient myWebClient =new WebClient(); 
                myWebClient.Credentials = CredentialCache.DefaultCredentials;             // 要上传的文件
                FileStream fs = new FileStream(localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1), FileMode.Open, FileAccess.Read); 
                BinaryReader r =new BinaryReader(fs); 
                try
               { 
                    //使用UploadFile方法可以用下面的格式 
                    //myWebClient.UploadFile(uriString,"PUT",localFilePath);
                    byte[] postArray = r.ReadBytes((int)fs.Length); 
                    Stream postStream = myWebClient.OpenWrite(uriString, "PUT"); 
                    if (postStream.CanWrite) 
                    { 
                        postStream.Write(postArray, 0, postArray.Length); 
                    }
                    else
                    { 
                        MessageBox.Show("文件目前不可写!"); 
                    }
                    postStream.Close(); 
                }
                catch
                { 
                    //MessageBox.Show("文件上传失败,请稍候重试~");
                    return false; 
                }            return true; 
            }唉,为了分啊
     
      

  6.   

    如何获得服务器路径呢?比如我想把图片上传到 ip 为192.168.0.3的D盘Images文件下??????????
      

  7.   


    /// <summary>
            /// 获取服务器IP
            /// </summary>
            /// <returns></returns>
            public static string GetIp()
            {
                string Ip = "";
                string strConn = DBUtil.SqlConnectionManager.ConnectionString();
                int startIndex = strConn.IndexOf("=") + 1;
                int endIndex = strConn.IndexOf(";");
                int totalLength = strConn.Length;
                int length = totalLength - startIndex - (totalLength - endIndex);
                Ip = strConn.Substring(startIndex, length);
                return Ip;
            }
      

  8.   

            try
               { 
                    //使用UploadFile方法可以用下面的格式 
                    //myWebClient.UploadFile(uriString,"PUT",localFilePath);
                    byte[] postArray = r.ReadBytes((int)fs.Length); 
                    Stream postStream = myWebClient.OpenWrite(uriString, "PUT"); 
                    if (postStream.CanWrite) 
                    { 
                        postStream.Write(postArray, 0, postArray.Length); 
                    }
                    else
                    { 
                        MessageBox.Show("文件目前不可写!"); 
                    }
                    postStream.Close(); 
    能不能给上面的代码加下注释啊?还有就是我Catch出来的错误是“无法连接到远程服务器”谢谢各位的关注了,本人确实分不多,希望大家可以谅解。能帮我把问题解决,O(∩_∩)O谢谢
      

  9.   

    http://www.cnblogs.com/vaiyanzi/archive/2008/11/20/1337465.html
      

  10.   

    您可以通过如下的方法实现从win application中upload file假设上传目录的物理路径为c:\upload,url为http://localhost/upload1.在IIS中upload虚拟目录属性中的directory security中的anonymous access and authentication control一栏中,点击edit,选中Anonymous access,并在virtual directory一栏选中write属性。2.将c:\upload目录属性中的Security设置为everyone3.在程序中使用如下的代码就可以实现file upload  WebClient myclient =  new WebClient();  myclient.UploadFile ("http://localhost/upload/odbc.ini","PUT","e:\\temp\\ODBC.INI");——微软全球技术中心 技术支持我只能做这么多了