当前位置:首页 » 文件传输 » 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>);
}
}