代码!100分!

解决方案 »

  1.   

    一般都是通过web services/WCF查询服务器进行升级   
    配置XML文件保存版本信息,查询服务器获取版本如是最新版本就不要升级   
    还可使用smart client   
    文件覆盖进行软件升级File.WriteAllText("test.bat",
    @"@echo off
    :run
    del %1 >nul
    if exist %1 goto run
    del test.bat
    ");
    ProcessStartInfo p= new ProcessStartInfo();
    p.FileName = "test.bat";
    p.Arguments = System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName;
    p.WindowStyle = ProcessWindowStyle.Hidden;
    Process.Start(p);http://topic.csdn.net/u/20090422/08/69f9713b-3982-4313-ab11-7fb6eefdcf93.html
      

  2.   

    最简单的是用 clickonce 部署代码。
      

  3.   

    1)原程序启动后检查版本号。如果不是最新的提示更新
    2)若更新程序,另起一个进程,进行文件的下载
    3)下载完成后提示,要求用户关闭当前程序,然后更新程序自动将文件复制到指定目录(或者替换原有文件)。
    4)替换完成后提示更新成功,启动原程序。新进程退出可采用Socket通信方式和.net框架的FtpWebRequest类来实现与FTP服务器通信和文件的下载,其中采用FtpWebRequest下载文件的部分代码如下,两种方式百度上都有代码,其中FtpWebRequest的客户端FTP类如下,其他的可以按着上面的步骤自己写
    class FTP_Class
        {
            string ftpServerIP;
            string ftpUserID;
            string ftpPassword;
            FtpWebRequest reqFTP;        public void Connecttest(string ftpServerIP, string ftpUserID, string ftpPassword)
            {
                // 根据uri创建FtpWebRequest对象
                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP));
                // 指定数据传输类型
                reqFTP.UseBinary = true;
                // ftp用户名和密码
                reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
            }        #region 连接
            /// <summary>
            /// 连接
            /// </summary>
            /// <param name="path"></param>
            private void Connect(String path)//连接ftp
            {
                // 根据uri创建FtpWebRequest对象
                reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(path));
                // 指定数据传输类型
                reqFTP.UseBinary = true;
                // ftp用户名和密码
                reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
            }
            #endregion
           
            #region ftp登录信息
            /// <summary>
            /// ftp登录信息
            /// </summary>
            /// <param name="ftpServerIP">ftpServerIP</param>
            /// <param name="ftpUserID">ftpUserID</param>
            /// <param name="ftpPassword">ftpPassword</param>
            public void FtpUpDown(string ftpServerIP, string ftpUserID, string ftpPassword)
            {
                this.ftpServerIP = ftpServerIP;
                this.ftpUserID = ftpUserID;
                this.ftpPassword = ftpPassword;
            }
            #endregion
            
            #region 获取文件列表
            /// <summary>
            /// 获取文件列表
            /// </summary>
            /// <param name="path"></param>
            /// <param name="WRMethods"></param>
            /// <returns></returns>
            private string[] GetFileList(string path, string WRMethods)//上面的代码示例了如何从ftp服务器上获得文件列表
            {
                string[] downloadFiles;
                StringBuilder result = new StringBuilder();
                try
                {
                    Connect(path);
                    reqFTP.Method = WRMethods;
                    WebResponse response = reqFTP.GetResponse();
                    StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8);//中文文件名
                    string line = reader.ReadLine();
                    while (line != null)
                    {
                        result.Append(line);
                        result.Append("\n");
                        line = reader.ReadLine();
                    }
                    // to remove the trailing '\n'
                    result.Remove(result.ToString().LastIndexOf('\n'), 1);
                    reader.Close();
                    response.Close();
                    return result.ToString().Split('\n');
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                    downloadFiles = null;
                    return downloadFiles;
                }
            }
            public string[] GetFileList(string path)//上面的代码示例了如何从ftp服务器上获得文件列表
            {
                return GetFileList("ftp://" + ftpServerIP + "/" + path, WebRequestMethods.Ftp.ListDirectory);
            }
            public string[] GetFileList()//上面的代码示例了如何从ftp服务器上获得文件列表
            {
                return GetFileList("ftp://" + ftpServerIP + "/", WebRequestMethods.Ftp.ListDirectory);
            }
            #endregion                                
            #region 下载文件
            /// <summary>
            /// 下载文件
            /// </summary>
            /// <param name="filePath"></param>
            /// <param name="fileName"></param>
            /// <param name="errorinfo"></param>
            /// <returns></returns>
            public bool Download(string ftpfilepath, string filePath, string fileName, out string errorinfo)////上面的代码实现了从ftp服务器下载文件的功能
            {
                try
                {
                    filePath = filePath.Replace("我的电脑\\", "");
                    String onlyFileName = Path.GetFileName(fileName);
                    string newFileName = filePath + onlyFileName;
                    if (File.Exists(newFileName))
                    {
                        errorinfo = string.Format("本地文件{0}已存在,无法下载", newFileName);
                        return false;
                    }
                    ftpfilepath = ftpfilepath.Replace("\\", "/");
                    string url = "ftp://" + ftpfilepath;
                    Connect(url);//连接 
                    reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
                    FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
                    Stream ftpStream = response.GetResponseStream();
                    long cl = response.ContentLength;
                    int bufferSize = 2048;
                    int readCount;
                    byte[] buffer = new byte[bufferSize];
                    readCount = ftpStream.Read(buffer, 0, bufferSize);
                    FileStream outputStream = new FileStream(newFileName, FileMode.Create);
                    while (readCount > 0)
                    {
                        outputStream.Write(buffer, 0, readCount);
                        readCount = ftpStream.Read(buffer, 0, bufferSize);
                    }
                    ftpStream.Close();
                    outputStream.Close();
                    response.Close();
                    errorinfo = "";
                    return true;
                }
                catch (Exception ex)
                {
                    errorinfo = string.Format("因{0},无法下载", ex.Message);
                    return false;
                }
            } 
            #endregion        
            
            #region 获得ftp上文件大小
            /// <summary>
            /// 获得ftp上文件大小
            /// </summary>
            /// <param name="filename"></param>
            /// <returns></returns>
            public long GetFileSize(string filename)
            {
                long fileSize = 0;
                filename = filename.Replace("\\","/");           
                try
                {
                   // FileInfo fileInf = new FileInfo(filename);
                    //string uri1 = "ftp://" + ftpServerIP + "/" + fileInf.Name;
                   // string uri = filename;
                    string uri = "ftp://" + filename;
                    Connect(uri);//连接      
                    reqFTP.Method = WebRequestMethods.Ftp.GetFileSize;
                    FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
                    fileSize = response.ContentLength;
                    response.Close();
                }
                catch (Exception ex)
                {
                    // MessageBox.Show(ex.Message);
                }
                return fileSize;
            }
            #endregion               #region 获得文件明晰
            /// <summary>
            /// 获得文件明晰
            /// </summary>
            /// <returns></returns>
            public string[] GetFilesDetailList()
            {
                return GetFileList("ftp://" + ftpServerIP + "/", WebRequestMethods.Ftp.ListDirectoryDetails);
            }
            /// <summary>
            /// 获得文件明晰
            /// </summary>
            /// <param name="path"></param>
            /// <returns></returns>
            public string[] GetFilesDetailList(string path)
            {
                path = path.Replace("\\", "/");
                return GetFileList("ftp://" + path, WebRequestMethods.Ftp.ListDirectoryDetails);
            }
            #endregion
            
        }
      

  4.   

    最简单的是用 clickonce 部署代码。
      

  5.   

    这个还用问啊,到精华帖里面找。
    顺手找给你算了
    http://topic.csdn.net/u/20090422/08/69f9713b-3982-4313-ab11-7fb6eefdcf93.html?77976
      

  6.   

    http://lovefly.blog.51cto.com/914912/273217
    这篇文章可以参考一下。不是我写的。