欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
WebClient上傳文件至服務(wù)器
在項目中用到了將WebClient上傳文件到服務(wù)器,經(jīng)在網(wǎng)上查找,自己添加到項目中進(jìn)行實(shí)驗了一番了,特將此代碼拷貝上來(lái):
/// <summary>
        /// WebClient上傳文件至服務(wù)器
        /// </summary>
        /// <param name="localFilePath">文件名,全路徑格式</param>
        /// <param name="serverFolder">服務(wù)器文件夾</param>
        /// <returns></returns>
        public static bool Upload(string localFilePath, string serverFolder, string newFileName)
        {
                  //獲取服務(wù)器的IP
                 string ip = PublicMethod.GetIp();
                if (!serverFolder.EndsWith("/") && !serverFolder.EndsWith(@"\"))
                {
                    serverFolder = serverFolder + "/";
                }
                string uriString = "http://" + ip + "/" + serverFolder + newFileName;
                /// 創(chuàng )建WebClient實(shí)例
                WebClient myWebClient = new WebClient();
                myWebClient.Credentials = CredentialCache.DefaultCredentials;
                // 要上傳的文件
                FileStream fs = new FileStream(localFilePath, FileMode.Open, FileAccess.Read);
                ////判斷文件大小
                //string strFileSize = DAL.DataBaseOperator.GetValueFromApplictionConfig("fileSize");
                //int fileSize = Convert.ToInt32(strFileSize) * 1024 * 1024;
                //if (fs.Length > fileSize)
                //{
                //    MessageBox.Show("您上傳的附件不能超過(guò) " + strFileSize + "M");
                //    return false;
                //}
                BinaryReader r = new BinaryReader(fs);
                //使用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("文件目前不可寫(xiě)!");
                }
                System.Windows.Forms.Application.DoEvents();
                postStream.Close();
            }
            catch (Exception err)
            {
                MessageBox.Show("文件上傳失敗,請稍候重試~");
                //DAL.Log.FileLogSys.FileLog.WriteLog(err.Message + err.StackTrace);
                return false;
            }
            return true;
        }
/// <summary>
        /// 獲取服務(wù)器的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;
        }
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
C# 中WinForm 應用程序實(shí)現遠程文件管理(上傳、下載)的種種問(wèn)題
c# 獲取本地主機的ip地址三種方法
獲取頁(yè)面中a標簽的地址并寫(xiě)入文件中
利用OleDb方式對DataSet 和 Excel 數據快速導入導出
WebClient類(lèi)--上傳文件
C# 通過(guò)DataGridView更新數據庫
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久