看了网上写的 用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. Linux pip 安装模块时,一直黄字错误:Could not find a version that satisfies the requirement

    参考原文:https://blog.csdn.net/u012592062/article/details/51966649 这时我们用国内的镜像源来加速 pip install 包名-i http: ...

  2. flask用session记录状态

    html <form action="/login" method="POST"> <input type="text" ...

  3. csharp:Microsoft.Ink 手写识别(HandWriting Recognition)

    /* 下載: //Microsoft Windows XP Tablet PC Edition 2005 Recognizer Pack http://www.microsoft.com/zh-cn/ ...

  4. linux系统下php扩展的安装

    0. 这里以php安装redis扩展为例 1. 首先下载并解压redis扩展包 [root@xxx ~]# cd /usr/local/src [root@xxx src]# wget https:/ ...

  5. 02_dubbo实例_多版本号

    [多版本作用] 当一个接口实现,出现不兼容升级时,可以用版本号过渡. 版本号不同的服务之间不能引用. [版本迁移方式] 1.在低压时间段,先升级一半Provider为新版本. 2.再将所有消费者升级为 ...

  6. Unity创建或克隆对象 Instantiate()

    //需要创建对象 GameObject prefab; //创建对象的规定位置或父物体 Transform tr; //创建出对象 Instantiate(prefab); //创建对象,并设定位置和 ...

  7. PHP 如何实现网址伪静态

    Apache的 mod_rewrite是比较强大的,在进行网站建设时,可以通过这个模块来实现伪静态. 主要步骤如下: 1.检测Apache是否开启mod_rewrite功能     可以通过php提供 ...

  8. Hadoop Archives档案

    HDFS 并不擅长存储小文件,因为每个文件最少一个 block,每个 block 的元数据都会在 NameNode 占用内存,如果存在大量的小文件,它们会吃掉NameNode 节点的大量内存. Had ...

  9. pt-duplicate-key-checker使用

    pt-duplicate-key-checker工具可以检测表中重复的索引,对于一些业务量很大的表,而且开发不规范的情况下有用.基本用法: 看一下我们的测试表: mysql> desc new_ ...

  10. 【Leetcode】【Medium】Minimum Path Sum

    Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...