ASP.NET WinForm C# 上传文件测试代码。
2012-04-08 00:26
465 查看
不废话,直接上代码。
save.aspx
save.cs
form1.cs
这样就实现了页面、winform窗口上传图片。
save.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="save.aspx.cs" Inherits="save" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>上传文件测试</title> <script language="javascript" type="text/javascript"> // <![CDATA[ function Button1_onclick() { document.getElementById("form1").submit(); } // ]]> </script> </head> <body> <form id="form2" runat="server"> <input id="File2" type="file" runat="server" /> <asp:Button ID="Button2" runat="server" Text="纯服务器端上传" /> </form> <form id="form1" action="save.aspx" method="post" enctype="multipart/form-data"> <input id="File1" name="File1" type="file" /> <input id="Button1" type="button" value="脚本控制上传" onclick="Button1_onclick()" /><br /> </form> <form id="form4" method="post" enctype="multipart/form-data" action="save.aspx"> <input id="testId" type="file" name="testName" /> <input id="testSubmit" type="submit" value="纯客户端上传" /> </form> </body> </html>
save.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; public partial class save : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Response.Write(Request.Files.Count.ToString()); if (Request.Files.Count > 0) { this.save_file(); } } private void save_file() { HttpPostedFile file = Request.Files[0]; Response.Write(file.FileName); file.SaveAs(Server.MapPath(Path.GetFileName(file.FileName))); } }
form1.cs
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Net; namespace WindowsFormsApplication2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { WebClient myWebClient = new WebClient(); byte[] result=myWebClient.UploadFile("http://localhost:1503/net4_test/save.aspx", "POST", @"D:/t.jpg"); } } }
这样就实现了页面、winform窗口上传图片。
相关文章推荐
- ASP.NET(C#)实现一次性动态上传多张图片的代码(多个文件)
- sql server 关于表中只增标识问题 C# 实现自动化打开和关闭可执行文件(或 关闭停止与系统交互的可执行文件) ajaxfileupload插件上传图片功能,用MVC和aspx做后台各写了一个案例 将小写阿拉伯数字转换成大写的汉字, C# WinForm 中英文实现, 国际化实现的简单方法 ASP.NET Core 2 学习笔记(六)ASP.NET Core 2 学习笔记(三)
- asp.net(C#)上传下载及文件管理代码
- asp.net(C#)上传下载及文件管理代码(续)
- ASP.NET(C#)实现一次性动态上传多张图片的代码(多个文件)
- ASP.NET(C#)实现一次性动态上传多张图片的代码(多个文件)
- Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)
- asp.net实现ftp上传代码(解决大文件上传问题)
- Winform(C#)——向服务器上传文件代码
- 在ASP.NET中实现多文件上传(C#)
- c# asp.net uploadify 上传大文件 出现的 HTTP 404 问题
- ASP.NET-文件上传代码
- Asp.net 2.0 用 FileUpload 控件实现多文件上传 用户控件(示例代码下载)
- asp.net 上传文件 实现【C#】
- asp.net,C#,FileUpload控件文件上传简单实例,vs2010
- ASP.NET 2.0(C#)文件上传
- Asp.net 2.0 用C# 创建 PDF文件[引用] (示例代码下载)
- 实现ASP.NET多文件上传程序代码
- ASP.NET(C#)FileUpload实现上传限定类型和大小的文件到服务器<from Copying>
- asp.net实现ftp上传代码(解决大文件上传问题)