導航:首頁 > 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上傳文件到伺服器相關的知識