當前位置:首頁 » 文件傳輸 » net上傳
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

net上傳

發布時間: 2022-03-14 16:40:27

⑴ .net 上傳文件

file 那個目錄存在了嗎

⑵ 如何上傳.net 網站

說不清楚,發給我,我給你傳
寫網路hi,給我,我在線,你在線情況下才行
這樣,您搜索一下.net 發布的問題Google,網路廣告多,您機器上有VS嗎,有的話方便很多,要不我說個時間吧,10點,您hi我,什麼你睡覺了,那我沒辦法了,什麼伺服器晚上不開,您叫我情何以堪,限制今天

⑶ c# .net文件上傳文件的源代碼

string path = Server.MapPath("/");
string filename = File.PostedFile.FileName; //獲得上傳文件全路徑
int place = filename.LastIndexOf(".") + 1; //獲得文件擴展名的位置
string year = DateTime.Now.Year.ToString(); //獲得系統時間的年
string month = DateTime.Now.Month.ToString(); //獲得系統時間的月
string day = DateTime.Now.Day.ToString(); //獲得系統時間的日
string hour = DateTime.Now.Hour.ToString(); //獲得系統時間的時
string min = DateTime.Now.Minute.ToString(); //獲得系統時間的分
string sec = DateTime.Now.Second.ToString(); //獲得系統時間的秒
string mill = DateTime.Now.Millisecond.ToString(); //獲得系統時間的毫秒
string extname = filename.Substring(place); //獲得上傳文件的擴展名
string fullname = year + month + day + hour + min + sec + mill + "." + extname;//重新生成圖片名
string imgpath = path + "BgManage/Proct/picture/" + fullname;//上傳文件的存放路徑
File.PostedFile.SaveAs(imgpath); //文件上傳

⑷ 用.NET開發程序實現上傳功能怎麼做

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// MyUpload 的摘要說明
/// </summary>
public class MyUpload
{
private System.Web.HttpPostedFile postedFile = null;
private string savePath = "";
private string[] extension;
private int fileLength = 0;
public string[] filestype ={ "txt", "doc", "gif" };
public MyUpload()
{
//
// TODO: 在此處添加構造函數邏輯
//
}
public string Help
{
get
{
string helpstring;
helpstring = "<font size=3>MyUpload myUpload=new MyUpload(); //構造函數";
helpstring += "myUpload.PostedFile=file1.PostedFile;//設置要上傳的文件";
helpstring += "myUpload.SavePath=\"e:\\\";//設置要上傳到伺服器的路徑,默認c:\\";
helpstring += "myUpload.FileLength=100; //設置上傳文件的最大長度,單位k,默認1k";
helpstring += "myUpload.Extension=\"doc\";設置上傳文件的擴展名,默認txt";
helpstring += "label1.Text=myUpload.Upload();//開始上傳,並顯示上傳結果";
helpstring += "<font size=3 color=red>";
return helpstring;
}

}

public System.Web.HttpPostedFile PostedFile
{
get
{
return postedFile;
}
set
{
postedFile = value;
}
}

public string SavePath
{
get
{
if (savePath != "") return savePath;
return "c:\\";
}
set
{
savePath = HttpContext.Current.Server.MapPath("../upimages/") + value;/////////////////////注意這里選取上傳文件路徑,可以修改成傳遞參數類型的
}
}

public int FileLength
{
get
{
if (fileLength != 0) return fileLength;
return 1024;
}
set
{
fileLength = value * 1024;
}
}

public string[] Extension
{
get
{
if (extension != null) return extension;
return filestype;
}
set
{
extension = value;
}
}

public string PathToName(string path)
{
int pos = path.LastIndexOf("\\");
return path.Substring(pos + 1);
}

public string Upload()
{
int biaoshi = 0;
if (PostedFile.FileName != "")
{
try
{
string fileName = PathToName(PostedFile.FileName);
for (int i = 0; i < Extension.Length; i++)
{
if (fileName.EndsWith(Extension[i]))
{
biaoshi = 1;
}
}
if (biaoshi != 1)
{
string errs = "";
for (int i = 0; i < Extension.Length; i++)
{
errs = errs + Extension[i] + "/";
}
return "您必須選擇" + errs + "類型的文件!";
}
if (PostedFile.ContentLength > FileLength) return "文件太大,超過了限定值!";
PostedFile.SaveAs(SavePath + DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + fileName.Substring(fileName.Length - 4, 4));
return DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + fileName.Substring(fileName.Length - 4, 4);
}
catch (System.Exception exc) { return exc.Message; }
}
return "請選擇文件後再進行上傳!";
}
}

////////////////////使用例子,直接復制沒有修改/////////////////////
string[] filestype ={ "gif", "jpg", "png" };
MyUpload myload = new MyUpload();
myload.PostedFile = File1.PostedFile;
myload.SavePath = "";
myload.FileLength = 1000;
myload.Extension = filestype;
Label1.Text = myload.Upload();
if (Label1.Text.StartsWith("200"))
{
Label2.Text = "upimages/" + Label1.Text;

Label1.Text = "上傳更新成功!";
}

⑸ .net 怎麼上傳文件

前台代碼:<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" runat="server" /><%--上傳文件的控制項--%>
<asp:Button ID="Button1" runat="server" OnClick="UploadFiles" Text="提交" /><%--提交上傳的文件--%>
</div>
</form>後台代碼
protected void UploadFiles(object sender, EventArgs e)
{
try
{
if (HttpContext.Current.Request.Files.Count > 0)
{
//System.Web.HttpPostedFile Provides access to indivial files that have been uploaded by a client.
HttpPostedFile postedFile = HttpContext.Current.Request.Files[0];//獲得用戶提交的文件

string savePath;
string dir = HttpContext.Current.Request.PhysicalApplicationPath;//當前應用程序的根目錄
savePath = dir + "Upload/DocumentFiles/";//保存文件的目錄,要事先添加,不會自己添加
string date = DateTime.Now.ToString("yyyy-M-d") + "-" + DateTime.Now.Hour.ToString() + "-" + DateTime.Now.Minute.ToString() + "-" + DateTime.Now.Second.ToString() + "-";//根據自己需要添加
savePath +=date+Path.GetFileName(postedFile.FileName);
if (File.Exists(savePath))
{
File.Delete(savePath);//如果文件已經存在就將已存在的文件刪除
}
postedFile.SaveAs(savePath);//將用戶提交的文件postedFile保存為savePath
}
}
catch (Exception ex)
{

}
}

⑹ 如何在ASP.NET上上傳視頻

protected bool btnFileUpload_Click()
{
Boolean fileOK = false;
//獲取上傳的文件名
string fileName = this.FileUpload1.FileName;
//獲取物理路徑
String path = Server.MapPath("images/");
//判斷上傳控制項是否上傳文件
if (FileUpload1.HasFile)
{
//判斷上傳文件的擴展名是否為允許的擴名".gif", ".png", ".jpeg", ".jpg" ,".bmp"
String fileExtension = System.IO.Path.GetExtension(fileName).ToLower();
String[] Extensions = { ".gif", ".png", ".jpeg", ".jpg", ".bmp" };
for (int i = 0; i < Extensions.Length; i++)
{
if (fileExtension == Extensions[i])
{
fileOK = true;
}
}
}
//如果上傳文件擴展名為允許的擴展名,則將文件保存在伺服器上指定的目錄中
if (fileOK)
{
try
{
ViewState["pic"] = "images/" + fileName.ToString();//獲取上傳成功後的路徑
this.FileUpload1.PostedFile.SaveAs(path + fileName);
return true;
//MessageBox("文件上傳完畢");
}
catch (Exception ex)
{
MessageBox("文件不能上傳,原因:" + ex.Message);
return false;
}
}
else
{
MessageBox("請正確的上傳圖片");
return false;
}
}

protected void MessageBox(string str)
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), "message", "<script language='javascript' defer>alert('" + str + "');</script>");
}

把擴展名改為你需要的就可以了

⑺ 如何把.net代碼上傳到伺服器

你保存的時候 指定了物理路徑 這點肯定不行 需使用Server.MapPath('文件路徑') 採用相對路徑存儲

⑻ ASP.net(C#)文件上傳功能

#region 附件上傳
/// <summary>
/// 附件上傳
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_Click(object sender, EventArgs e)
{
string filename = this.FileUpload1.PostedFile.FileName;
string filetype = this.FileUpload1.PostedFile.ContentType;
if (FileUpload1.HasFile)
{

string newfilename = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Day.ToString() + System.DateTime.Now.Minute.ToString() + System.DateTime.Now.Second.ToString() + filename.Substring(filename.LastIndexOf("."), filename.Length - filename.LastIndexOf("."));
int len = filename.Length - filename.LastIndexOf("\\") - 1;
filename = filename.Substring(filename.LastIndexOf("\\") + 1, len);
string strPath = Server.MapPath("..\\..\\" + "uploadfile\\");
this.FileUpload1.PostedFile.SaveAs(strPath + newfilename);
this.Label3.Text = "..\\..\\uploadfile\\" + newfilename;
this.Label4.Visible = true;
}
else
{
Response.Write("<script>alert('請選擇上傳的附件!')</script>");
}
}
#endregion

⑼ .net實現文件上傳到伺服器

1、前端界面十分簡單,只是放一個file類型的和一個按鈕,並且為這個按鈕添加點擊事件(btnUpLoad_Click),如下圖:

protectedvoidbtnUpLoad_Click(objectsender,EventArgse)
{
//取出所選文件的本地路徑
stringfullFileName=this.UpLoad.PostedFile.FileName;
//從路徑中截取出文件名
stringfileName=fullFileName.Substring(fullFileName.LastIndexOf()+1);
//限定上傳文件的格式
stringtype=fullFileName.Substring(fullFileName.LastIndexOf(.)+1);
if(type==doc||type==docx||type==xls||type==xlsx||type==ppt||type==pptx||type==pdf||type==jpg||type==bmp||type==gif||type==png||type==txt||type==zip||type==rar)
{
//將文件保存在伺服器中根目錄下的files文件夾中
stringsaveFileName=Server.MapPath(/files)++fileName;
UpLoad.PostedFile.SaveAs(saveFileName);
Page.ClientScript.RegisterStartupScript(Page.GetType(),message,<scriptlanguage='javascript'defer>alert('文件上傳成功!');</script>);

//向資料庫中存儲相應通知的附件的目錄
BLL.news.InsertAnnexBLLinsertAnnex=newBLL.news.InsertAnnexBLL();
AnnexEntityannex=newAnnexEntity();//創建附件的實體
annex.AnnexName=fileName;//附件名
annex.AnnexContent=saveFileName;//附件的存儲路徑
annex.NoticeId=noticeId;//附件所屬「通知」的ID在這里為已知
insertAnnex.InsertAnnex(annex);//將實體存入資料庫(其實就是講實體的這些屬性insert到資料庫中的過程,具體BLL層和DAL層的代碼這里不再多說)
}
else
{
Page.ClientScript.RegisterStartupScript(Page.GetType(),message,<scriptlanguage='javascript'defer>alert('請選擇正確的格式');</script>);
}
}