当前位置: 首页>>代码示例>>C#>>正文


C# System.Net.WebClient.UploadFile方法代码示例

本文整理汇总了C#中System.Net.WebClient.UploadFile方法的典型用法代码示例。如果您正苦于以下问题:C# System.Net.WebClient.UploadFile方法的具体用法?C# System.Net.WebClient.UploadFile怎么用?C# System.Net.WebClient.UploadFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.WebClient的用法示例。


在下文中一共展示了System.Net.WebClient.UploadFile方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendKML

        public static void SendKML(string guid)
        {
            try
            {
                using (System.Net.WebClient client = new System.Net.WebClient())
                {
                    client.Credentials = new System.Net.NetworkCredential("[email protected]", "zacne.123");
                    client.UploadFile("ftp://zacne.c0.pl/" + "/" + new FileInfo(@"D:\KML\" + guid + ".kml").Name, "STOR", @"D:\KML\" + guid + ".kml");
                }
            }

            catch (Exception ex)
            {
                string xxx = ex.Message;
            }
        }
开发者ID:Simon323,项目名称:PlacePick,代码行数:16,代码来源:KMLProvider.cs

示例2: Savecopy

        void Savecopy(Player p, string message)
        {
            if (message.EndsWith("#"))
            {
                if (!p.group.CanExecute(Command.all.Find("copysavenet")))
                {
                    Player.SendMessage(p, "You are not allowed to save to network locations.");
                    return;
                }
                message = message.Remove(message.Length - 1);
                byte[] cnt = new byte[p.CopyBuffer.Count * 7];
                int k = 0;
                for (int i = 0; i < p.CopyBuffer.Count; i++)
                {
                    BitConverter.GetBytes(p.CopyBuffer[i].x).CopyTo(cnt, 0 + k);
                    BitConverter.GetBytes(p.CopyBuffer[i].y).CopyTo(cnt, 2 + k);
                    BitConverter.GetBytes(p.CopyBuffer[i].z).CopyTo(cnt, 4 + k);
                    cnt[6 + k] = p.CopyBuffer[i].type;  //BitConverter.GetBytes(p.CopyBuffer[i].type).CopyTo(cnt, 6 + k);
                    k = k + 7;
                }
                cnt = cnt.GZip();
                if (!message.StartsWith("http://", true, System.Globalization.CultureInfo.CurrentCulture)) message = "http://" + message;
                try
                {
                    string savefile = "temp" + p.name + new Random().Next(999) + ".cpy";
                    using (FileStream fs = new FileStream(savefile, FileMode.Create))
                    {
                        fs.Write(cnt, 0, cnt.Length);
                    }
                    using (System.Net.WebClient webup = new System.Net.WebClient())
                    {
                        webup.UploadFile(message, savefile);
                        //webup.UploadData(message, cnt);
                    }
                    File.Delete(savefile);
                    Player.SendMessage(p, "Saved copy to " + message + "/" + savefile);
                }
                catch (Exception e) { Player.SendMessage(p, "Failed to upload " + message + e); }
                return;
            }

            if (Player.ValidName(message))
            {
                if (!Directory.Exists("extra/savecopy")) Directory.CreateDirectory("extra/savecopy");
                if (!Directory.Exists("extra/savecopy/" + p.name)) Directory.CreateDirectory("extra/savecopy/" + p.name);
                if (Directory.GetFiles("extra/savecopy/" + p.name).Length > 14) { Player.SendMessage(p, "You can only save 15 copy's. /copy delete some."); return; }
                using (FileStream fs = new FileStream("extra/savecopy/" + p.name + "/" + message + ".cpy", FileMode.Create))
                {
                    byte[] cnt = new byte[p.CopyBuffer.Count * 7];
                    int k = 0;
                    for (int i = 0; i < p.CopyBuffer.Count; i++)
                    {
                        BitConverter.GetBytes(p.CopyBuffer[i].x).CopyTo(cnt, 0 + k);
                        BitConverter.GetBytes(p.CopyBuffer[i].y).CopyTo(cnt, 2 + k);
                        BitConverter.GetBytes(p.CopyBuffer[i].z).CopyTo(cnt, 4 + k);
                        cnt[6 + k] = p.CopyBuffer[i].type;  //BitConverter.GetBytes(p.CopyBuffer[i].type).CopyTo(cnt, 6 + k);
                        k = k + 7;
                    }
                    cnt = cnt.GZip();
                    fs.Write(cnt, 0, cnt.Length);
                    fs.Flush();
                    fs.Close();
                }
                Player.SendMessage(p, "Saved copy as " + message);
            }
            else Player.SendMessage(p, "Bad file name");
        }
开发者ID:AnthonyANI,项目名称:MCForge-MCLawl,代码行数:67,代码来源:CmdCopy.cs

示例3: subValidateCustomProfileData

        private void subValidateCustomProfileData()
        {
            //download custom data for parents of campers that were submitted through the online registration system.

            string strFile = DateTime.Now.ToString("yyyyMMdd_hhmmss") + "_" + clsAppSettings.GetAppSettings().lngCTUserID.ToString() + "_ProfileIDs.xml";
            string strFileName = System.IO.Path.GetDirectoryName(Properties.Settings.Default.MainPath) + "\\" + strFile;
            string strWebFile = "C:\\inetpub\\wwwroot\\camptrak.com\\fileuls\\" + strFile;
            string strSQL = "";

            using (OleDbConnection conDB = new OleDbConnection(clsAppSettings.GetAppSettings().strCTConn))
            {
                conDB.Open();

                strSQL = "SELECT tblWebRecords.lngProfileWebID " +
                        "FROM tblWebRecords " +
                        "WHERE tblWebRecords.lngProfileWebID Is Not Null";

                using (OleDbCommand cmdDB = new OleDbCommand(strSQL, conDB))
                {
                    using (OleDbDataAdapter daProfile = new OleDbDataAdapter(cmdDB))
                    {
                        DataSet dsProfile = new DataSet();

                        daProfile.Fill(dsProfile);

                        dsProfile.WriteXml(strFileName);
                    }
                }

                conDB.Close();
            }

            //put file
            bool blnULRes = false;
            string strULRes = "";

            try
            {
                System.Net.WebClient cliUL = new System.Net.WebClient();

                byte[] bytULRes = cliUL.UploadFile(clsAppSettings.GetAppSettings().strPOSTFileURI, strFileName);

                // Decode and display the response.

                try { strULRes = System.Text.Encoding.ASCII.GetString(bytULRes); }
                catch { strULRes = "ERR"; }

                blnULRes = true;
            }
            catch (Exception ex)
            {
                lstDLStatus.Items.Insert(0, DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + ": Error uploading XML file: " + ex.Message);
                Application.DoEvents();
                blnULRes = false;
            }

            if (blnULRes)
            {
                //tell web service to generate data
                using (wsXferEventInfo.XferEventInfo svc = new global::CTWebMgmt.wsXferEventInfo.XferEventInfo())
                {
                    strULRes = svc.fcnGetCustomData(strWebFile, clsAppSettings.GetAppSettings().strWebDBConn, clsAppSettings.GetAppSettings().lngCTUserID);
                }

                if (strULRes.EndsWith(".xml"))
                {
                    //retrieve results
                    using (System.Net.WebClient webClient = new System.Net.WebClient())
                        webClient.DownloadFile("https://www.camptrak.com/fileuls/CustomData/" + strULRes, System.IO.Path.GetDirectoryName(Properties.Settings.Default.MainPath) + "\\" + strULRes);

                    //insert or edit data in table
                    using (OleDbConnection conDB = new OleDbConnection(clsAppSettings.GetAppSettings().strCTConn))
                    {
                        conDB.Open();

                        using (OleDbCommand cmdDB = new OleDbCommand())
                        {
                            cmdDB.Connection = conDB;

                            Type[] dataTypes = { typeof(Record), typeof(CustomField) };

                            //serialize objres to file
                            System.Xml.Serialization.XmlSerializer xsrRes = new System.Xml.Serialization.XmlSerializer(typeof(CustomRecordData), dataTypes);

                            using (Stream reader = new FileStream(System.IO.Path.GetDirectoryName(Properties.Settings.Default.MainPath) + "\\" + strULRes, FileMode.Open))
                            {
                                CustomRecordData crdFromServer;

                                crdFromServer = (CustomRecordData)xsrRes.Deserialize(reader);

                                for (int intRecord = 0; intRecord < crdFromServer.Records.Count; intRecord++)
                                {
                                    long lngRecordWebID = 0;

                                    try { lngRecordWebID = crdFromServer.Records[intRecord].RecordWebID; }
                                    catch { lngRecordWebID = 0; }

                                    if (lngRecordWebID > 0)
                                    {
                                        for (int intCustomField = 0; intCustomField < crdFromServer.Records[intRecord].CustomFields.Count; intCustomField++)
//.........这里部分代码省略.........
开发者ID:khallgren,项目名称:CTWebMgmt,代码行数:101,代码来源:frmDLIndReg.cs

示例4: subSaveCustomFieldDefReg


//.........这里部分代码省略.........

                            cmdDB.Parameters.AddWithValue("@blnUseLocal", blnUseLocal);
                            cmdDB.Parameters.AddWithValue("@lngSortOrder", lngSortOrder);
                            cmdDB.Parameters.AddWithValue("@decCharge", decCharge);
                            cmdDB.Parameters.AddWithValue("@strLocalCaption", strLocalCaption);
                            cmdDB.Parameters.AddWithValue("@lngCustomFieldDefRegID", lngCustomFieldDefRegID);

                            cmdDB.ExecuteNonQuery();

                            //build xml of web data to commit
                            bool blnRequired = false;
                            string strWebCaption = "";
                            string strHeader = "";
                            string strFooter = "";

                            try { blnRequired = ((CheckBox)panCustomReg.Controls["chkRequiredReg_" + lngCustomFieldDefRegID.ToString()]).Checked; }
                            catch { blnRequired = false; }

                            try { strWebCaption = ((TextBox)panCustomReg.Controls["txtWebCaptionReg_" + lngCustomFieldDefRegID.ToString()]).Text; }
                            catch { strWebCaption = ""; }

                            try { strHeader = ((TextBox)panCustomReg.Controls["txtHeaderReg_" + lngCustomFieldDefRegID.ToString()]).Text; }
                            catch { strHeader = ""; }

                            try { strFooter = ((TextBox)panCustomReg.Controls["txtFooterReg_" + lngCustomFieldDefRegID.ToString()]).Text; }
                            catch { strFooter = ""; }

                            if (strWebCaption != "" && ((CheckBox)panCustomReg.Controls["chkUseOnlineReg_"+lngCustomFieldDefRegID.ToString()]).Checked)
                            {
                                //generate xml of definition
                                xmlOut.WriteStartElement("CustomFieldDefReg");

                                xmlOut.WriteElementString("lngCTUserID", clsAppSettings.GetAppSettings().lngCTUserID.ToString());
                                xmlOut.WriteElementString("lngCustomFieldDefRegID", lngCustomFieldDefRegID.ToString());
                                xmlOut.WriteElementString("blnRequired", blnRequired.ToString());
                                xmlOut.WriteElementString("lngProgramID", _lngProgramID.ToString());
                                xmlOut.WriteElementString("lngSortOrder", lngSortOrder.ToString());
                                xmlOut.WriteElementString("decCharge", decCharge.ToString());
                                xmlOut.WriteElementString("strLocalCaption", strLocalCaption);
                                xmlOut.WriteElementString("strWebCaption", strWebCaption);
                                xmlOut.WriteElementString("strHeader", strHeader);
                                xmlOut.WriteElementString("strFooter", strFooter);
                                xmlOut.WriteElementString("strFieldType", strFieldType);

                                //write dd options
                                xmlOut.WriteStartElement("strDropdownOptions");

                                List<string> strDropdownOptions = new List<string>(((TextBox)panCustomReg.Controls["txtDropdownOptionsReg_" + lngCustomFieldDefRegID.ToString()]).Text.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries));

                                for (int intOption = 0; intOption < strDropdownOptions.Count; intOption++)
                                    xmlOut.WriteElementString("strValue", strDropdownOptions[intOption]);

                                xmlOut.WriteEndElement();

                                xmlOut.WriteEndElement();
                            }
                        }

                        xmlOut.WriteEndElement();
                        xmlOut.WriteEndDocument();
                    }

                    conDB.Close();
                }
            }

            //upload xml doc of web field defs
            using (wsXferEventInfo.XferEventInfo xferEventInfo = new global::CTWebMgmt.wsXferEventInfo.XferEventInfo())
            {
                string strWebRes = "";

                System.Net.WebClient myWebClient = new System.Net.WebClient();

                string fileName = strFileName;

                try
                {
                    byte[] responseArray = myWebClient.UploadFile(clsWebTalk.strPOSTFileURI, fileName);

                    // Decode and display the response.
                    string strULRes = "";

                    try { strULRes = System.Text.Encoding.ASCII.GetString(responseArray); }
                    catch { strULRes = "ERR"; }

                    //tell server to process uploaded file
                    strWebRes = xferEventInfo.fcnCommitCustomFieldDefReg(strWebFile, clsWebTalk.strWebConn);
                }
                catch (System.Net.WebException ex)
                {
                    Console.WriteLine(ex.Message);
                }

                if (strWebRes != "")
                    MessageBox.Show("There was an error uploading the custom flag and field definitions to the web server.");
            }

            //delete temp local file
            System.IO.File.Delete(strFileName);
        }
开发者ID:khallgren,项目名称:CTWebMgmt,代码行数:101,代码来源:frmSyncCustomFlags.cs

示例5: fcnCommitDiscountsToWeb

        private bool fcnCommitDiscountsToWeb()
        {
            bool blnRes = false;

            string strFile = DateTime.Now.ToString("yyyyMMdd") + "_" + clsAppSettings.GetAppSettings().lngCTUserID.ToString() + "DiscountDef.xml";
            string strFileName = System.IO.Path.GetDirectoryName(Properties.Settings.Default.MainPath) + "\\" + strFile;

            string strWebFile = clsWebTalk.strPOSTFileDir + strFile;

            using (XmlWriter xmlOut = XmlWriter.Create(strFileName))
            {
                xmlOut.WriteStartDocument();
                xmlOut.WriteStartElement("DiscountDef");
                xmlOut.WriteAttributeString("CTUserID", clsAppSettings.GetAppSettings().lngCTUserID.ToString());

                //generate xml of definition
                for (int intI = 1; intI <= 10; intI++)
                {
                    xmlOut.WriteStartElement("Discount");
                    xmlOut.WriteElementString("DiscountID", intI.ToString());
                    xmlOut.WriteElementString("Description", ((TextBox)Controls["txtDiscount" + intI.ToString()]).Text);
                    xmlOut.WriteElementString("PromoCode", ((TextBox)Controls["txtPromoCode" + intI.ToString()]).Text);
                    xmlOut.WriteElementString("Amount", ((TextBox)Controls["txtDiscountAmt" + intI.ToString()]).Text.Replace("$", ""));
                    xmlOut.WriteElementString("Display", ((CheckBox)Controls["chkDisplayOnline" + intI.ToString()]).Checked.ToString());
                    xmlOut.WriteEndElement();
                }

                xmlOut.WriteEndElement();
                xmlOut.WriteEndDocument();
            }

            using (wsXferEventInfo.XferEventInfo xferEventInfo = new global::CTWebMgmt.wsXferEventInfo.XferEventInfo())
            {
                string strWebRes = "";

                //upload file

                // Create a new WebClient instance.
                System.Net.WebClient myWebClient = new System.Net.WebClient();

                // Upload the file to the URI.
                // The 'UploadFile(uriString,fileName)' method implicitly uses HTTP POST method.

                try
                {
                    byte[] responseArray = myWebClient.UploadFile(clsWebTalk.strPOSTFileURI, strFileName);

                    // Decode and display the response.
                    string strULRes = "";

                    try { strULRes = System.Text.Encoding.ASCII.GetString(responseArray); }
                    catch { strULRes = "ERR"; }

                    strWebRes = xferEventInfo.fcnCommitDiscountDefs(strWebFile, clsWebTalk.strWebConn);
                }
                catch (System.Net.WebException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                //upload xml definition file...web server will process it and return result.
                if (strWebRes != "")
                    MessageBox.Show("There was an error uploading the discount definitions to the web server.");
                else
                    blnRes = true;
            }

            //delete temp file
            System.IO.File.Delete(strFileName);

            return blnRes;
        }
开发者ID:khallgren,项目名称:CTWebMgmt,代码行数:71,代码来源:frmDiscounts.cs

示例6: WebClientPostFile

 /// <summary>
 /// POST文件到服务器
 /// </summary>
 /// <param name="PostUrl"></param>
 /// <param name="postfilename"></param>
 private static void WebClientPostFile(string PostUrl, string postfilename)
 {
     System.Net.WebClient myWebClient = new System.Net.WebClient();
     byte[] result = myWebClient.UploadFile(PostUrl, "POST", postfilename);
     string alert = System.Text.Encoding.Default.GetString(result, 0, result.Length);
 }
开发者ID:no10pc,项目名称:Light,代码行数:11,代码来源:Utility.cs

示例7: fcnULImg

        private bool fcnULImg(string _strLocFileToUL)
        {
            bool blnRes = false;

            string strULRes = "";

            try
            {
                System.Net.WebClient cliUL = new System.Net.WebClient();

                byte[] bytULRes = cliUL.UploadFile(clsWebTalk.strPOSTFileURI, _strLocFileToUL);

                // Decode and display the response.
                try { strULRes = System.Text.Encoding.ASCII.GetString(bytULRes); }
                catch { strULRes = "ERR"; }

                using (wsXferEventInfo.XferEventInfo wsXfer = new global::CTWebMgmt.wsXferEventInfo.XferEventInfo())
                {
                    string strFileName = "";

                    long lngWeekID = 0;
                    long lngCampID = 0;
                    long lngHousingID = 0;

                    try { strFileName = _strLocFileToUL.Substring(_strLocFileToUL.LastIndexOf("\\") + 1, _strLocFileToUL.Length - (_strLocFileToUL.LastIndexOf("\\") + 1)); }
                    catch { strFileName = _strLocFileToUL; }

                    try { lngWeekID = ((clsCboItem)cboWeek.SelectedItem).ID; }
                    catch { lngWeekID = 0; }

                    try { lngCampID = ((clsCboItem)cboProgram.SelectedItem).ID; }
                    catch { lngCampID = 0; }

                    try { lngHousingID = ((clsCboItem)cboHousing.SelectedItem).ID; }
                    catch { lngHousingID = 0; }

                    try
                    {
                        string strWebDBConn = "Server=localhost;Database=dbCTOnline;UID=WebMailAdmin;PWD=tS3UnhYa;";

                        string strRes = wsXfer.fcnCommitMsgImgUL(strFileName, clsAppSettings.GetAppSettings().lngCTUserID, lngWeekID, lngCampID, lngHousingID, strWebDBConn);

                        if (strRes == "")
                            blnRes = true;
                        else
                        {
                            blnRes = false;
                            lblStatus.Text = "Error committing image " + strRes;
                        }
                    }
                    catch(Exception ex)
                    {
                        blnRes = false;
                        lblStatus.Text = "ERROR Commiting Image: " + ex.Message;
                    }
                }
            }
            catch (Exception ex)
            {
                lblStatus.Text = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + ": Error uploading XML file: " + ex.Message;

                Application.DoEvents();
                blnRes = false;
            }

            return blnRes;
        }
开发者ID:khallgren,项目名称:CTWebMgmt,代码行数:67,代码来源:frmImgUL.cs

示例8: ActionUploadFile

        /// <summary>
        /// Upload log file
        /// </summary>
        public void ActionUploadFile()
        {
            ActionFlush();

            System.Net.WebClient Client = new System.Net.WebClient();
            Client.Headers.Add("Content-Type", "binary/octet-stream");
            byte[] result = Client.UploadFile(Properties.Settings.Default.uploadUrl, "POST", Properties.Settings.Default.logFile);
            string s = System.Text.Encoding.UTF8.GetString(result, 0, result.Length);

            return;
        }
开发者ID:lftkv,项目名称:KeyLogger,代码行数:14,代码来源:analyzer.cs

示例9: Main


//.........这里部分代码省略.........
                }
            } catch (Exception e) {
                exc = e;
                outFile.WriteLine ("Name: " + tempPath + "\\dummyFile15.txt");
                outFile.WriteLine ("Func: " + "System.IO.IsolatedStorage.IsolatedStorageFileStream.ctor(String, FileMode)");
                outFile.WriteLine ("Proc: " + System.Diagnostics.Process.GetCurrentProcess ().Id);
                outFile.WriteLine ("Time: " + GetTime (now));
                outFile.WriteLine ("Retv: " + toString (isfs));
                outFile.WriteLine ("Errc: " + "");
                outFile.WriteLine ("Exce: " + GetException (exc));
            }

            try {
                System.Net.WebClient wc = new System.Net.WebClient ();
                try {
                    exc = null;
                    now = System.DateTime.Now;
                    wc.DownloadFile ("http://www.google.com", tempPath + "\\dummyFile16.txt");
                } catch (Exception e) {
                    exc = e;
                } finally {
                    outFile.WriteLine ("Name: " + tempPath + "\\dummyFile16.txt");
                    outFile.WriteLine ("Func: " + "System.Net.WebClient.DownloadFile(String, String)");
                    outFile.WriteLine ("Proc: " + System.Diagnostics.Process.GetCurrentProcess ().Id);
                    outFile.WriteLine ("Time: " + GetTime (now));
                    outFile.WriteLine ("Retv: " + "");
                    outFile.WriteLine ("Errc: " + "");
                    outFile.WriteLine ("Exce: " + GetException (exc));
                }
                try {
                    exc = null;
                    bL = null;
                    now = System.DateTime.Now;
                    bL = wc.UploadFile ("http://www.google.com", tempPath + "\\dummyFile16.txt");
                } catch (Exception e) {
                    exc = e;
                } finally {
                    outFile.WriteLine ("Name: " + tempPath + "\\dummyFile16.txt");
                    outFile.WriteLine ("Func: " + "System.Net.WebClient.UploadFile(String, String)");
                    outFile.WriteLine ("Proc: " + System.Diagnostics.Process.GetCurrentProcess ().Id);
                    outFile.WriteLine ("Time: " + GetTime (now));
                    outFile.WriteLine ("Retv: " + toString (bL));
                    outFile.WriteLine ("Errc: " + "");
                    outFile.WriteLine ("Exce: " + GetException (exc));
                }
            } catch (Exception) {
            }

            try {
                string processString = null;
                try {
                    exc = null;
                    p = null;
                    now = System.DateTime.Now;
                    p = System.Diagnostics.Process.Start (tempPath + "\\dummyFile16.txt");
                    processString = toString (p);
                    p.Kill ();
                } catch (Exception e) {
                    exc = e;
                } finally {
                    outFile.WriteLine ("Name: " + tempPath + "\\dummyFile16.txt");
                    outFile.WriteLine ("Func: " + "System.Diagnostics.Process.Start(String)");
                    outFile.WriteLine ("Proc: " + System.Diagnostics.Process.GetCurrentProcess ().Id);
                    outFile.WriteLine ("Time: " + GetTime (now));
                    outFile.WriteLine ("Retv: " + processString);
                    outFile.WriteLine ("Errc: " + "");
开发者ID:uvbs,项目名称:Holodeck,代码行数:67,代码来源:TestApplication4.cs


注:本文中的System.Net.WebClient.UploadFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。