本文整理汇总了C#中WebClient.UploadFile方法的典型用法代码示例。如果您正苦于以下问题:C# WebClient.UploadFile方法的具体用法?C# WebClient.UploadFile怎么用?C# WebClient.UploadFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebClient
的用法示例。
在下文中一共展示了WebClient.UploadFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UploadFile
private void UploadFile(string filetype)
{
if (filetype == "VIDEO") //TODO:CONFIG
RadUpload1.TargetFolder = ConfigurationManager.AppSettings["VideoUploadPath"].ToString(); //TODO:CONFIG
if (filetype == "AUDIO") //TODO:CONFIG
RadUpload1.TargetFolder = ConfigurationManager.AppSettings["AudioUploadPath"].ToString(); //TODO:CONFIG
if (filetype != "")
{
string path = string.Empty;
string name = hdnName.Value;
string fn = System.IO.Path.GetFileName(name);
string extension = fn.Substring(fn.IndexOf("."));
string savefile = Guid.NewGuid().ToString() + extension;
string SaveLocation = path + savefile;
//FileUpload.PostedFile.SaveAs(SaveLocation);
//Session["FileName"] = savefile;
WebClient Client = new WebClient();
//RadUpload1.AllowedFileExtensions = {'.flv'};
//Client.UploadFile(Server.MapPath(RadUpload1.TargetFolder) + savefile, name);
Client.UploadFile(RadUpload1.TargetFolder + savefile, name);
//Session.Remove("PostedFile");
//Make database entry.
//if (FilePathFileUpload.HasFile)
//{
VideoInfo entity = new VideoInfo();
//string appPath = Server.MapPath(ConfigurationManager.AppSettings.Get("VideoUploadPath"));
//string extension = FilePathFileUpload.PostedFile.FileName.Substring(FilePathFileUpload.PostedFile.FileName.LastIndexOf("."));
//entity.FilePath = System.Guid.NewGuid().ToString() + extension;
//FilePathFileUpload.SaveAs(appPath + entity.FilePath);
//if (Session["FileName"] != null)
if (savefile != "")
{
//entity.FilePath = Session["FileName"].ToString();
//Session["FileName"] = null;
entity.FilePath = savefile;
}
entity.ClassId = this.ClassId;
entity.Title = TitleTextBox.Text;
entity.Description = DescriptionTextBox.Value;
//entity.Speakers = SpeakerTextBox.Text;
entity.Visible = VisibleCheckBox.Checked;
entity.CreatedTimestamp = DateTime.Now;
entity.UpdatedTimestamp = DateTime.Now;
bool result = VideoInfo.InsertVideo(ref entity);
if (result)
{
//CreateVideoDialog.Reset();
DataBind();
OnVideoCreated(EventArgs.Empty);
entity = null;
//Session.Remove("FileName");
Response.Redirect(this.Page.Request.Url.AbsoluteUri);
}
}
}
示例2: UpFile
/// <summary>
/// WebClient.UploadFile()
/// </summary>
public static void UpFile()
{
WebClient client = new WebClient();
client.UploadFile("http://www.baidu.com", "C:/Users/yk199/Desktop/GodWay1/Web/Log/newfile.txt");
byte[] image = new byte[2];
client.UploadData("http://www.baidu.com",image);
}
示例3: UploadFile
/// <summary>
/// Загружает файл на заданный Url
/// </summary>
/// <param name="uploadUrl">Адрес для загрузки</param>
/// <param name="path">Путь к файлу</param>
/// <returns>Cтрока, используемая далее в Vk API</returns>
public static string UploadFile(string uploadUrl, string path)
{
using (var client = new WebClient())
{
var answer = Encoding.UTF8.GetString(client.UploadFile(uploadUrl, path));
var json = JObject.Parse(answer);
var rawResponse = json["file"];
return new VkResponse(rawResponse) { RawJson = answer };
}
}
示例4: Upload
//Establishes a connection to the server and uploads the specified file
public void Upload(String filePath, String name)
{
try {
using (WebClient webClient = new WebClient())
{
webClient.Credentials = new NetworkCredential(Login, Password);
byte[] b = webClient.UploadFile(Address + "//" + name, "STOR", filePath);
}
}
catch(Exception e)
{
}
}
示例5: UpLoadLog
public static void UpLoadLog()
{
m_bIsUpdate = true;
fInfo = new FileStream(datapath,FileMode.Create,FileAccess.Write,FileShare.ReadWrite);
writer = new StreamWriter(fInfo);
writer.Write(LogText);
writer.Flush();
fInfo.Flush();
writer.Close();
fInfo.Close();
WebClient Tmp = new WebClient();
Tmp.UploadFile("http://bbs.enveesoft.com:84/brave/index.php/site/logwrite",datapath);
Debug.Log ("UpLoad_Log");
m_bIsUpdate = false;
}
示例6: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
string name = Session["PostedFile"].ToString();
string fn = System.IO.Path.GetFileName(name);
string extension = fn.Substring(fn.IndexOf("."));
string savefile = Guid.NewGuid().ToString() + extension;
string SaveLocation = path + savefile;
//FileUpload.PostedFile.SaveAs(SaveLocation);
Session["FileName"] = savefile;
WebClient Client = new WebClient();
Client.UploadFile(Server.MapPath("~/ClassRoom/MyFiles") + "/"+ savefile, name);
//FileUpload.Attributes.Add("onkeypress", "return false;");
//FileUpload.Attributes.Add("onkeydown", "return false;");
Session.Remove("PostedFile");
}
示例7: UploadFileAsync
protected override Task<byte[]> UploadFileAsync(WebClient wc, string address, string fileName) => Task.Run(() => wc.UploadFile(address, fileName));
示例8: ConcurrentOperations_Throw
public static async Task ConcurrentOperations_Throw()
{
await LoopbackServer.CreateServerAsync((server, url) =>
{
var wc = new WebClient();
Task ignored = wc.DownloadDataTaskAsync(url); // won't complete
Assert.Throws<NotSupportedException>(() => { wc.DownloadData(url); });
Assert.Throws<NotSupportedException>(() => { wc.DownloadDataAsync(url); });
Assert.Throws<NotSupportedException>(() => { wc.DownloadDataTaskAsync(url); });
Assert.Throws<NotSupportedException>(() => { wc.DownloadString(url); });
Assert.Throws<NotSupportedException>(() => { wc.DownloadStringAsync(url); });
Assert.Throws<NotSupportedException>(() => { wc.DownloadStringTaskAsync(url); });
Assert.Throws<NotSupportedException>(() => { wc.DownloadFile(url, "path"); });
Assert.Throws<NotSupportedException>(() => { wc.DownloadFileAsync(url, "path"); });
Assert.Throws<NotSupportedException>(() => { wc.DownloadFileTaskAsync(url, "path"); });
Assert.Throws<NotSupportedException>(() => { wc.UploadData(url, new byte[42]); });
Assert.Throws<NotSupportedException>(() => { wc.UploadDataAsync(url, new byte[42]); });
Assert.Throws<NotSupportedException>(() => { wc.UploadDataTaskAsync(url, new byte[42]); });
Assert.Throws<NotSupportedException>(() => { wc.UploadString(url, "42"); });
Assert.Throws<NotSupportedException>(() => { wc.UploadStringAsync(url, "42"); });
Assert.Throws<NotSupportedException>(() => { wc.UploadStringTaskAsync(url, "42"); });
Assert.Throws<NotSupportedException>(() => { wc.UploadFile(url, "path"); });
Assert.Throws<NotSupportedException>(() => { wc.UploadFileAsync(url, "path"); });
Assert.Throws<NotSupportedException>(() => { wc.UploadFileTaskAsync(url, "path"); });
Assert.Throws<NotSupportedException>(() => { wc.UploadValues(url, new NameValueCollection()); });
Assert.Throws<NotSupportedException>(() => { wc.UploadValuesAsync(url, new NameValueCollection()); });
Assert.Throws<NotSupportedException>(() => { wc.UploadValuesTaskAsync(url, new NameValueCollection()); });
return Task.CompletedTask;
});
}
示例9: UploadFile_InvalidArguments_ThrowExceptions
public static void UploadFile_InvalidArguments_ThrowExceptions()
{
var wc = new WebClient();
Assert.Throws<ArgumentNullException>("address", () => { wc.UploadFile((string)null, null); });
Assert.Throws<ArgumentNullException>("address", () => { wc.UploadFile((string)null, null, null); });
Assert.Throws<ArgumentNullException>("address", () => { wc.UploadFile((Uri)null, null); });
Assert.Throws<ArgumentNullException>("address", () => { wc.UploadFile((Uri)null, null, null); });
Assert.Throws<ArgumentNullException>("address", () => { wc.UploadFileAsync((Uri)null, null); });
Assert.Throws<ArgumentNullException>("address", () => { wc.UploadFileAsync((Uri)null, null, null); });
Assert.Throws<ArgumentNullException>("address", () => { wc.UploadFileAsync((Uri)null, null, null, null); });
Assert.Throws<ArgumentNullException>("address", () => { wc.UploadFileTaskAsync((string)null, null); });
Assert.Throws<ArgumentNullException>("address", () => { wc.UploadFileTaskAsync((string)null, null, null); });
Assert.Throws<ArgumentNullException>("address", () => { wc.UploadFileTaskAsync((Uri)null, null); });
Assert.Throws<ArgumentNullException>("address", () => { wc.UploadFileTaskAsync((Uri)null, null, null); });
Assert.Throws<ArgumentNullException>("fileName", () => { wc.UploadFile("http://localhost", null); });
Assert.Throws<ArgumentNullException>("fileName", () => { wc.UploadFile("http://localhost", null, null); });
Assert.Throws<ArgumentNullException>("fileName", () => { wc.UploadFile(new Uri("http://localhost"), null); });
Assert.Throws<ArgumentNullException>("fileName", () => { wc.UploadFile(new Uri("http://localhost"), null, null); });
Assert.Throws<ArgumentNullException>("fileName", () => { wc.UploadFileAsync(new Uri("http://localhost"), null); });
Assert.Throws<ArgumentNullException>("fileName", () => { wc.UploadFileAsync(new Uri("http://localhost"), null, null); });
Assert.Throws<ArgumentNullException>("fileName", () => { wc.UploadFileAsync(new Uri("http://localhost"), null, null, null); });
Assert.Throws<ArgumentNullException>("fileName", () => { wc.UploadFileTaskAsync("http://localhost", null); });
Assert.Throws<ArgumentNullException>("fileName", () => { wc.UploadFileTaskAsync("http://localhost", null, null); });
Assert.Throws<ArgumentNullException>("fileName", () => { wc.UploadFileTaskAsync(new Uri("http://localhost"), null); });
Assert.Throws<ArgumentNullException>("fileName", () => { wc.UploadFileTaskAsync(new Uri("http://localhost"), null, null); });
}
示例10: uploadFile
public static void uploadFile(NameValueCollection getParamters, string uri, string fileName)
{
WebClient myWebClient = new WebClient();
myWebClient.QueryString = getParamters;
byte[] responseArray = myWebClient.UploadFile(uri, "POST", fileName);
string result = System.Text.Encoding.UTF8.GetString(responseArray);
Debug.Log("File uploaded : " + result);
}
示例11: LoginGUI
//This method will login the accounts.
private void LoginGUI ()
{
if (showInventory) {
GUI.Box (new Rect (550, 160, 300, 400), "Send email");
// From (email)
GUI.Label (new Rect (590, 180, 220, 23), "From (email):");
fromEmail = GUI.TextField (new Rect (590, 200, 220, 23), fromEmail);
// From (name)
GUI.Label (new Rect (590, 220, 220, 23), "From (name):");
fromName = GUI.TextField (new Rect (590, 240, 220, 23), fromName);
// From (password)
GUI.Label (new Rect (590, 260, 220, 23), "Paswword (sender):");
fromPassword = GUI.PasswordField (new Rect (590, 280, 220, 23), fromPassword, "*" [0]);
// Subject
GUI.Label (new Rect (590, 300, 220, 23), "Subject :");
fromSubject = GUI.TextField (new Rect (590, 320, 220, 23), fromSubject);
// Message
GUI.Label (new Rect (590, 340, 220, 23), "Message :");
scrollPosition = GUI.BeginScrollView (new Rect (590, 360, 220, 200), scrollPosition, new Rect (0, 0, 200, 200));
fromBody = GUI.TextArea (new Rect (0, 00, 220, 70), fromBody);
GUI.EndScrollView ();
if(GUIButton_scripts.clientType == "worker"){
// Attachement
GUI.Label (new Rect (590, 430, 220, 23), "Attache file :");
fromAttachement = GUI.TextField (new Rect (640, 450, 170, 23), fromAttachement);
if (GUI.Button (new Rect (590, 450, 45, 23), "Open")) {
OpenFileName ofn = new OpenFileName ();
ofn.structSize = Marshal.SizeOf (ofn);
ofn.filter = "All Files\0*.*\0\0";
ofn.file = new string (new char[256]);
ofn.maxFile = ofn.file.Length;
ofn.fileTitle = new string (new char[64]);
ofn.maxFileTitle = ofn.fileTitle.Length;
ofn.initialDir = UnityEngine.Application.dataPath;
ofn.title = "Attache file to your email";
ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;
//OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST| OFN_ALLOWMULTISELECT|OFN_NOCHANGEDIR
if (DllOpen.GetOpenFileName (ofn)) {
fromAttachement = ofn.file;
}
}
}
// To (email)
GUI.Label (new Rect (590, 470, 220, 23), "To (email):");
toEmail = GUI.TextField (new Rect (590, 490, 220, 23), toEmail);
if (GUI.Button (new Rect (590, 520, 120, 25), "Send")) {
sereverIP += ConnectionHandler_scripts.ip+":80";
if(GUIButton_scripts.clientType == "worker"){
WebClient client = new WebClient();
client.UploadFile(sereverIP+"/sendMail/upload.php", "POST", fromAttachement);
}
string filename = Path.GetFileName(fromAttachement);
string loginURL = sereverIP+"/sendMail/mail.php?from="+fromName+"&fromName="+fromEmail+"&password="+fromPassword+"&to="
+toEmail+"&subject="+fromSubject+"&body="+fromBody+"&file="+filename;
Debug.Log(loginURL);
WWW w = new WWW(loginURL);
StartCoroutine(login(w));
}
}
}//End Login GUI
示例12: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
//이제 수정할거 -> 올릴때 movie1 , 2 , 3 .... 이런식으로 되도록
string fileName = FileUpload1.FileName; //파일 이름
string filePath = FileUpload1.PostedFile.FileName; //파일 경로
string[] tmp = filePath.Split('\\');
string upperPath="";
for (int i = 0; i < tmp.Length; i++)
upperPath += tmp[i];
string[] fileExtention = fileName.Split('.'); // 파일 이름을 .으로 분리
string fileInfo = fileExtention[1];//파일 확장자
//String timeStr = getDurationMedia(filePath);
//int hours = int.Parse(timeStr) / 3600, minutes = (int.Parse(timeStr) % 3600 / 60), seconds = (int.Parse(timeStr) % 3600 % 60);
conn = new MySqlConnection(connStr);
try
{
conn.Open();
int count = 0;
DataSet ds = new DataSet();
if (conn.State == ConnectionState.Open)
{
string query = "SELECT VIDEO_NUM FROM UPLOAD_VIDEO";
MySqlDataAdapter adpt = new MySqlDataAdapter(query, conn);
adpt.Fill(ds, "UPLOAD_VIDEO");
if (ds.Tables.Count > 0)
{
foreach (DataRow r in ds.Tables[0].Rows)
{
count++;
}
}
ds.Reset();
}
count++;
string category = DayList.SelectedItem.Text + "," + EraList.SelectedItem.Text + "," + PlaceList.SelectedItem.Text + "," +
SeasonList.SelectedItem.Text + "," + AgeList.SelectedItem.Text + "," + SexList.SelectedItem.Text + "," + JobList.SelectedItem.Text + "," +
IncidList.SelectedItem.Text;
//string sql = "INSERT INTO UPLOAD_VIDEO(VIDEO_NUM,TITLE,FILE_TYPE,RUNNING_TIME,FILE_PATH,MADE_BY,CATEGORY,THUMBNAIL_PATH) VALUES(" +
// count + ",'" + fileName + "','" + fileInfo + "','" + hours.ToString() + ":" + minutes.ToString() + ":" + seconds.ToString() +
// "','" + fileName + "','" + currentID + "','" + category + "','" + (fileName + "_thumbnail.jpg") + "')";
string sql = "INSERT INTO UPLOAD_VIDEO(VIDEO_NUM,TITLE,FILE_TYPE,FILE_PATH,MADE_BY,CATEGORY,THUMBNAIL_PATH) VALUES(" +
count + ",'" + fileName + "','" + fileInfo + "','" + fileName + "','" + currentID + "','" + category + "','" + (fileName + "_thumbnail.jpg") + "')";
conn = new MySqlConnection(connStr);
cmd = new MySqlCommand(sql, conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
catch (Exception ex)
{
Label1.Text = "Error" + ex.Message.ToString();
}
using (WebClient client = new WebClient())
{
client.Credentials = new NetworkCredential("dcs", "ghkdlxld");
client.UploadFile("ftp://203.241.249.106" + "/" + new FileInfo(filePath).Name, "STOR", filePath);
(new NReco.VideoConverter.FFMpegConverter()).GetVideoThumbnail(filePath, filePath + "_thumbnail.jpg");
client.UploadFile("ftp://203.241.249.106" + "/" + new FileInfo(filePath + "_thumbnail.jpg").Name, "STOR", filePath + "_thumbnail.jpg");
}
}
示例13: upload
public static void upload(string fil)
{
if (fil != null || fil != "")
{
string fn = Path.GetFileName(fil);
if (!folderToBrowse.EndsWith("/"))
folderToBrowse = folderToBrowse + "/";
string fp = folderToBrowse + fn;
WebClient wc = new WebClient();
try
{
byte[] responseArray = wc.UploadFile(fp, fil);
System.Text.Encoding.ASCII.GetString(responseArray);
}
catch (Exception e)
{
}
}
}
示例14: HTTPUploadFile
public string HTTPUploadFile(string url, string local_file_path)
{
string xml = null;
try
{
WebClient Client = new WebClient();
Client.UploadFile(url, local_file_path);
}
catch (Exception ex)
{
string message = ex.Message;
return message;
}
return xml;
}
示例15: uploadFile
public static string uploadFile(string filename,string access_token,string type)
{
WebClient c = new WebClient();
//string filename = @"文件路径";
byte[] result = c.UploadFile(new Uri(String.Format("http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token="+access_token+"&type="+type)), filename);
string resultjson = Encoding.Default.GetString(result);
return resultjson;
}