国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

.net下軟件的自動升級--上傳

2024-07-10 12:59:07
字體:
供稿:網(wǎng)友
.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 窗體設(shè)計器生成的代碼
override protected void oninit(eventargs e)
{
//
// codegen: 該調(diào)用是 asp.net web 窗體設(shè)計器所必需的。
//
initializecomponent();
base.oninit(e);
}

/// <summary>
/// 設(shè)計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內(nèi)容。
/// </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;

//得到這個文件的相關(guān)屬性:文件名,文件類型,文件大小
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里"/"為轉(zhuǎn)義字符,必須用"//"代替
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>



發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 常德市| 宜阳县| 敦化市| 和静县| 无锡市| 扎鲁特旗| 晴隆县| 小金县| 托里县| 葵青区| 股票| 泾川县| 驻马店市| 麻城市| 邯郸县| 封开县| 阿勒泰市| 隆回县| 香港| 德阳市| 宁明县| 忻城县| 新干县| 富源县| 拉萨市| 米脂县| 晋城| 盐亭县| 通化县| 东丰县| 普格县| 鄄城县| 启东市| 黄大仙区| 长兴县| 子长县| 甘孜| 卓资县| 新昌县| 页游| 满城县|