看了网上写的 用webclient类的uploadfile方法,

我在本地建立了个webform,winform窗体,  现在可以本地实现文件传递,可以选择文件传到d:\temp路径下,但怎们传到服务器上就不会了

求教大神

webform code

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; public partial class SiteMaster : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
foreach (string f in Request.Files.AllKeys)
{
HttpPostedFile file = Request.Files[f];
file.SaveAs(@"D:\Temp\" +file.FileName);
}
if (Request.Params["testKey"] != null)
{
Response.Write(Request.Params["testKey"]);
}
}
}

winform code:

 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.IO;
using System.Net;
using System.Web; namespace 上传
{
public partial class UpLoadForm : Form
{
public UpLoadForm()
{
InitializeComponent();
}
private void btn_select_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Multiselect = true;
if (ofd.ShowDialog() == DialogResult.OK)
{
this.txtpath.Text = ofd.FileName;
}
}
private void btn_Upload_Click(object sender, EventArgs e)
{
if (this.txtpath.EditValue != null)
{
UpLoadFile("http://localhost:61750/WebSite3/Default.aspx", "POST", this.txtpath.Text.Trim());
// UpLoadFile("\\192.168.5.71", "POST", this.txtpath.Text.Trim());
}
else
{
MessageBox.Show("请选择上传文件");
} }
public void UpLoadFile(string Serverpath, string Mode, string Localpath)
{
try
{
WebClient mywebcilent = new WebClient();
mywebcilent.UploadFile(Serverpath,Mode,Localpath);
MessageBox.Show("上传成功");
}
catch
{
MessageBox.Show("上传失败");
}
} }
}

winform 里 如何实现文件上传的更多相关文章

  1. php文件上传之单文件上传

    为了简单一些,php文件跟form表单写在了一个文件里. php单文件上传----> <!DOCTYPE html> <html> <head> <me ...

  2. C# 文件上传(可以多文件上传)

    一.前端搭建 1.前端用到js:uploadify(下载地址:http://www.uploadify.com/download/).layer (下载地址:http://layer.layui.co ...

  3. java基础巩固之java实现文件上传

      对于文件上传,浏览器在上传的过程中是将文件以流的形式提交到服务器端的,如果直接使用Servlet获取上传文件的输入流然后再解析里面的请求参数是比较麻烦,所以一般选择采用apache的开源工具com ...

  4. PHPcms v9.6.0 文件上传漏洞

    title: PHPcms v9.6.0 文件上传漏洞 date: 2021-4-5 tags: 渗透测试,CVE漏洞复现,文件上传 categories: 渗透测试 CVE漏洞复现 文件上传 PHP ...

  5. winform程序压缩文件上传,服务器端asp.net mvc进行接收解压

    期间编程没什么难度,唯一可能忽略导致结果失败是asp.net  mvc配置 对于压缩文件大的话,需要配置mvc的最大接收量: <system.web> <httpRuntime ma ...

  6. 本文档教授大家在yii2.0里实现文件上传 首先我们来实现单文件上传

    第一步  首先建立一个关于上传的model层  如果你有已经建好的可以使用表单小部件的model层 也可以直接用这个.在这里我们新建一个新的model层 在model层新建文件  Upload.php ...

  7. Winform文件上传

    近期在做了一个winform的项目的附件上传的需求 最初项目选型的时候有三种 1.使用webservice.webapi上传文件 2,直接保存在数据库中 3.使用共享目录+dos命令 第一种有文件大小 ...

  8. C# WinForm 文件上传下载

    /// <summary> /// WebClient上传文件至服务器 /// </summary> /// <param name="fileNamePath ...

  9. winform 更新文件上传(一)

    using Common; using DevExpress.XtraEditors; using FileModel.UpLoad; using System; using System.Colle ...

随机推荐

  1. 在mysql语句中为什么要加反引号

    在MySQL语句中我们有时候经常会遇到反引号(``),刚开始的时候不知道什么意思,他是什么作用呢? Select * from `member` order by posts desc limit 0 ...

  2. thinkphp session设置

    <?php namespace Home\Controller; use think\Controller; /*登录*/ class LoginController extends Publi ...

  3. thinkphp 手机号和用户名同时登录

    //在注册时用户名不能是纯数字, 防止一个人的用户名和另一个人的手机号相同public function Login(){ if (IS_AJAX) { $username = I('param.us ...

  4. C# 索引器的使用

    索引器允许类或者结构的实例按照与数组相同的方式进行索引取值,索引器与属性类似,不同的是索引器的访问是带参的. 索引器和数组比较: (1)索引器的索引值(Index)类型不受限制 (2)索引器允许重载 ...

  5. 日常捕获的野生知识 - javascript 与 类

    javascript 并不提供类这样方便实用的面向对象类型,今天学习到了,直接上代码: <!DOCTYPE html> <html lang="en"> & ...

  6. 制作rpm安装包

    1.安装rpmbuild软件 sudo apt-get install rpmbuild2.配置工作路径 在制作 rpm 包之前,首先要配置工作路径,也就是制作 rpm 包所在的目录.制作 rpm 包 ...

  7. linux 安装源码后的操作 ldconfig

    https://blog.csdn.net/cqkxboy168/article/details/8657487 知识点: .如果使用 ldd 命令时没有找到对应的共享库文件和其具体位置,可能是两种情 ...

  8. idea 使用 git打成jar包到 nexus

    1.使用idea生成jar包参考:http://blog.csdn.net/eastgrand/article/details/11945309 2.进入到 自己的工程目录(含有pom.xml的目录) ...

  9. 快速安装测试版Mysql

    本文操作系统: CentOS 7.2.1511 x86_64MySQL 版本: 5.7.13 1.卸载系统自带的 mariadb-lib [root@centos-linux ~]# rpm -qa| ...

  10. 一次查找sqlserver死锁的经历

    查找bug是程序员的家常便饭,我身边的人喜欢让用户来重现问题.当然他们也会从正式服务器上下载错误log,然后尝试分析log,不过当错误不是那种不经思考就可识别的情况,他们就会将问题推向用户,甚至怪罪程 ...