导航:首页 > IDC知识 > cwinform上传文件到服务器

cwinform上传文件到服务器

发布时间:2020-10-26 09:32:38

1、C#(WinForm)上传图片到服务器

代码在附件里面

只要数据库中存储了,

前台调用对你应该不是问题,

另网上也有不少这类的源码

你可以自己在搜搜,这样对你问题的解决问题能得到提升的

希望我的回答对你有帮助

若帮助到您的话,请及时采纳哈

2、C# winform 如何将文件远程上传到服务器上的网站文件夹?

在网上查查上传图片的代码。介绍jmail的上传附件的就有 下面的是按钮点击方法
html:

<asp:FileUpload ID="fufujian" runat="server" style ="border-left-style:none;border-right-style:none;border-top-style:none; " />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />

********************************************************************************************************************************************************************************************************************
.cs文件
按钮点击

if (fufujian.HasFile)
{
//指定上传文件在服务器上的保存路径
string savePath = Server.MapPath("~/upload/");
//检查服务器上是否存在这个物理路径,如果不存在则创建
if (!System.IO.Directory.Exists(savePath))
{
//需要注意的是,需要对这个物理路径有足够的权限,否则会报错
//另外,这个路径应该是在网站之下,而将网站部署在C盘却把上传文件保存在D盘
System.IO.Directory.CreateDirectory(savePath);
}
savePath = savePath + "\\" + fufujian.FileName;
fufujian.SaveAs(savePath);//保存文件
//不过需要注意的是,在客户端访问却需要指定的是URL地址,而不是在服务器上的物理地址
// Response.Write(savePath);
// Response.End();
//Response.Write(string.Format("<a href='upload/{0}'>upload/{0}</a>", fufujian.FileName));
//Response.End();

3、C#+winform,客户端实现大文件上传到服务器,跪求源代码,很急

用webservice 上传 百度搜

4、c#如何实现将文件上传到服务器?求详细代码?谢了

<tr>
<td width="60%" align="right">
<asp:FileUpload ID="UserFile" runat="server" />
</td>
<td align="left" >

<asp:Button ID="UserImport" runat="server" Text="学生人员信息导入"
onclick="UserImport_Click" />
</td>
</tr>
protected void UserImport_Click(object sender, EventArgs e)
{

string fileName = UserFile.FileName; 获取上传的文件的名称
string path = Server.MapPath("~/ImportExcelFile/"); //存储在服务器的路径
if (!Directory.Exists(path)) //判断路径是否存在 不存在创建
{
Directory.CreateDirectory(path);
}
string savePath = path + fileName; 这是 文件保存到服务器 文件的整体路径
UserFile.SaveAs(savePath); 上传保存OK
}

简单易懂明白了吗?
希望帮到你

5、winform怎么上传文件到服务器,需要代码

System.Net.WebClient webclient = new System.Net.WebClient();
webclient.UploadFile(URL, FileName);

URL 是服务器的URL,就是接受文件的那个页面,FileName是本地文件。所以服务器还必须有个版能接受文件上传权的页面。JSP与 ASP.NET都可以通用。

6、C#中如何实现文件上传服务器。

例子:
//获取openFileDialog控件选择的文件名数组(openFileDialog可多个文件选择)
private void button1_Click(object sender, EventArgs e)
{
label1.Text = "";
try
{
this.openFileDialog1.ShowDialog();
path = this.openFileDialog1.FileNames; //获取openFileDialog控件选择的文件名数组
string strpath = "";
for (int y = 0; y < path.Length; y++)
{
strpath += path[y];
}
textBox1.Text = strpath;
}
catch
{
this.lbl_ftpStakt.Text = "请选择文件!";
}
}
//上传按钮事件
private void button2_Click(object sender, EventArgs e)
{
this.lbl_ftpStakt.Visible = true; //设置上传信息标签可见
this.lbl_ftpStakt.Text = "连接服务器...";

try
{
for (i = 0; i < path.Length; i++)
{
filename = path[i].ToString();

//实例化事件类
myTest fo = new myTest(filename);
fo.startUpEvent+=new myTest.myUpEventsHandler(this.RunsOnWorkerThread); //注册事件
fo.mythreadStart(); //调用类的方法

FileInfo p = new FileInfo(path[i].ToString());
uploadSQL(p.Name); //上传到库
}
//label1.Text = "上传成功";
}
catch
{
string s="";
for (int x = i; x < path.Length; x++)
{
FileInfo file = new FileInfo(path[i].ToString());
s += file.Name + " ";
}
this.lbl_ftpStakt.Text = "上传失败";
MessageBox.Show(s.ToString()+" 上传失败","提示");
}
}
//连接ftp上传
public void RunsOnWorkerThread(string _filename)
{
//阻塞线程
mt.WaitOne();
Interlocked.Increment(ref flag); //状态值+1

this.lbl_ftpStakt.Text = "连接服务器中...";
FileInfo fileInf = new FileInfo(_filename);
FtpWebRequest reqFTP;
// 根据uri创建FtpWebRequest对象
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://210.82.***.***/" + fileInf.Name));
// ftp用户名和密码
reqFTP.Credentials = new NetworkCredential("record", "files");
// 默认为true,连接不会被关闭
// 在一个命令之后被执行
reqFTP.KeepAlive = false;
// 指定执行什么命令
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
// 指定数据传输类型
reqFTP.UseBinary = true;
// 上传文件时通知服务器文件的大小
reqFTP.ContentLength = fileInf.Length;
//long _length = fileInf.Length; /////////
// 缓冲大小设置为2kb
int buffLength = 2048; ////
byte[] buff = new byte[buffLength];
int contentLen;
// 打开一个文件流 (System.IO.FileStream) 去读上传的文件
FileStream fs = fileInf.OpenRead();

try
{
// 把上传的文件写入流
Stream strm = reqFTP.GetRequestStream();
// 每次读文件流的2kb
contentLen = fs.Read(buff, 0, buffLength);
int allbye = (int)fileInf.Length;
int startbye = 0;
this.myProgressControl.Maximum = allbye;
this.myProgressControl.Minimum = 0;
this.myProgressControl.Visible = true;
this.lbl_ftpStakt.Visible = true;
this.lbl_ftpStakt.Text = "服务器连接中...";
// 流内容没有结束
while (contentLen != 0)
{
// 把内容从file stream 写入 upload stream
strm.Write(buff, 0, contentLen);
contentLen = fs.Read(buff, 0, buffLength);
startbye += contentLen;
this.lbl_ftpStakt.Text = "已上传:" + (int)(startbye / 1024) + "KB/" + "总长度:" + (int)(allbye / 1024) + "KB" + " " + " 文件名:" + fileInf.Name;
myProgressControl.Value = startbye;
}
// 关闭两个流
strm.Close();
fs.Close();
this.myProgressControl.Visible = false;
this.lbl_ftpStakt.Text = "上传成功!";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Upload Error");
}
Interlocked.Decrement(ref flag);
mt.ReleaseMutex();//释放线程
}

/// <summary>
/// 委托事件类
/// </summary>
class myTest
{
public string filename;
public delegate void myUpEventsHandler(string _filename);
public event myUpEventsHandler startUpEvent;

public myTest()
{
}

/// <summary>
///
/// </summary>
/// <param name="_filename">上传的文件名</param>
public myTest(string _filename)
{
this.filename = _filename;
}

/// <summary>
/// 开始一个线程,执行事件
/// </summary>
public void mythreadStart()
{
Thread thr = new Thread(new ThreadStart(this.mystart));
thr.Start();
}

/// <summary>
/// 开始事件
/// </summary>
public void mystart()
{
startUpEvent(this.filename);
}
}

7、C# winform如何用代码实现上传文件到外网服务器

步骤一:获取文件大小并上传服务器。然后,服务器创建相同大小
第二步的字节数组:使用的FileStream字节读取图像文件。

第三步:步骤发送字节读取。

对于大文件可以使用每个字节的固定循环阅读。如果内存无法进行一次性读取。
这些基本步骤。不要复制的源代码,所以你不能学到东西。

8、C# winform如何实现批量上传文件到远程服务器?

批量上传 就是多线程同时开启多文件上传咯。

我想是否可以是: C#的多线程 + webclient类(或许要用更复杂的类代替)。

9、C#winform怎么上传文件到服务器

/// <summary> 
        /// 上传 
        /// </summary> 
        /// <param name="filename">要上传的本地文件名</param> 
        public void Upload(string filename)
        {
            FileInfo fileInf = new FileInfo(filename);
            string uri = ftpURI + fileInf.Name;
            FtpWebRequest reqFTP;
 
            reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri));
            reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
            reqFTP.KeepAlive = false;
            reqFTP.Proxy = null;
            reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
            reqFTP.UseBinary = true;
            reqFTP.ContentLength = fileInf.Length;
            int buffLength = 2048;
            byte[] buff = new byte[buffLength];
            int contentLen;
            FileStream fs = fileInf.OpenRead();
            try
            {
                Stream strm = reqFTP.GetRequestStream();
                contentLen = fs.Read(buff, 0, buffLength);
                while (contentLen != 0)
                {
                    strm.Write(buff, 0, contentLen);
                    contentLen = fs.Read(buff, 0, buffLength);
                }
                strm.Close();
                fs.Close();
            }
            catch (Exception ex)
            {
                Error_Log("FTP上传文件时发成错误,详细错误参数请查看错误日志。", "Upload Error --> " + ex.Message + " " + ex.StackTrace);
            }
        }

10、C#winform 上传图片到服务器

看看来这个是否适合:
C#.Net 上传源图片,限制图片大小,检查类型
www.csframework.com/archive/2/arc-2-20110716-1727.htm
这个肯定适合,C# Winform 图片资源上传下载WebApi服务器,好像收费
www.csframework.com/archive/1/arc-1-20171021-2381.htm

与cwinform上传文件到服务器相关的知识