欢迎光临
我们一直在努力

.net下软件的自动升级–上传-.NET教程,.NET Framework

建站超值云服务器,限时71元/月

.net下软件的自动升级–上传

代码如下:

upload.aspx.cs

using system;

using system.collections;

using system.componentmodel;

using system.data;

using system.drawing;

using system.web;

using system.web.sessionstate;

using system.web.ui;

using system.web.ui.webcontrols;

using system.web.ui.htmlcontrols;

using system.io;

namespace uploadnote

{

/// <summary>

/// webform1 的摘要说明。

/// </summary>

public class upload : system.web.ui.page

{

protected system.web.ui.webcontrols.label fname;

protected system.web.ui.webcontrols.label fenc;

protected system.web.ui.webcontrols.label fsize;

protected system.web.ui.webcontrols.label labelerror;

protected system.web.ui.htmlcontrols.htmlinputfile myfile;

protected system.web.ui.htmlcontrols.htmlinputbutton button1;

private void page_load(object sender, system.eventargs e)

{

// 在此处放置用户代码以初始化页面

if(labelerror.text != "")

{

labelerror.text = "";

}

}

#region web 窗体设计器生成的代码

override protected void oninit(eventargs e)

{

//

// codegen: 该调用是 asp.net web 窗体设计器所必需的。

//

initializecomponent();

base.oninit(e);

}

/// <summary>

/// 设计器支持所需的方法 – 不要使用代码编辑器修改

/// 此方法的内容。

/// </summary>

private void initializecomponent()

{

this.button1.serverclick += new system.eventhandler(this.button1_serverclick);

this.load += new system.eventhandler(this.page_load);

}

#endregion

private void button1_serverclick(object sender, system.eventargs e)

{

//检查上传文件不为空

if(myfile.postedfile.filename !="")

{

string fullname = myfile.postedfile.filename;

//得到这个文件的相关属性:文件名,文件类型,文件大小

this.fname.text = myfile.postedfile.filename;

this.fenc.text = myfile.postedfile.contenttype;

this.fsize.text = myfile.postedfile.contentlength.tostring() + “ bytes“;

//取得文件名(抱括路径)里最后一个"\"的索引

int j = fullname.lastindexof("\\");

//取得文件名

string simplename = fullname.substring(j);

//保存文件到你所要的目录,这里是iis根目录下的uploadnote目录.你可以改变.

//用server.mappath()取当前文件的绝对目录.在asp.net里"\"为转义字符,必须用"\\"代替

string filepath = server.mappath("\\uploadnote");

//myfile.postedfile.saveas("d:\\test\\aa.doc");

myfile.postedfile.saveas(filepath + simplename);

// response.write(server.machinename);

}

else

{

labelerror.text = "请选择要上传的文件!";

}

}

}

}

upload.aspx

<%@ page language="c#" debug="true" codebehind="upload.aspx.cs" autoeventwireup="false" inherits="uploadnote.upload" %>

<!doctype html public "-//w3c//dtd html 4.0 transitional//en" >

<html>

<head>

<title>文件上传</title>

<meta content="microsoft visual studio .net 7.1" name="generator">

<meta content="c#" name="code_language">

<meta content="javascript" name="vs_defaultclientscript">

<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetschema">

</head>

<body ms_positioning="gridlayout">

<form id="uploderform" action="upload.aspx" method="post" runat="server">

<table cellspacing="2" cellpadding="2" align="center" border="1" width="580" height="400">

<tr>

<td><asp:label id="labelerror" runat="server"></asp:label>

</td>

</tr>

<tr>

<td>

<table width="564">

<tr>

<td>选择要上传的文件:</td>

</tr>

<tr>

<td><input id="myfile" type="file" name="myfile" runat="server" style="width: 480px; height: 22px"

size="60">

</td>

</tr>

<tr>

<td><input id="button1" type="button" value="上 传" name="button1" runat="server"></td>

</tr>

</table>

<br>

<table width="564">

<tr>

<td width="200"><b>文件资料</b></td>

<td>&nbsp;</td>

</tr>

<tr>

<td>文件名 :</td>

<td><asp:label id="fname" runat="server" text=""></asp:label></td>

</tr>

<tr>

<td>文件类型 :</td>

<td><asp:label id="fenc" runat="server"></asp:label></td>

</tr>

<tr>

<td>文件大小 :</td>

<td><asp:label id="fsize" runat="server"></asp:label></td>

</tr>

</table>

</td>

</tr>

</table>

</form>

</body>

</html>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » .net下软件的自动升级–上传-.NET教程,.NET Framework
分享到: 更多 (0)

相关推荐

  • 暂无文章