Visual C#是微软公司.Ner FrameWork框架中的一个重要组成部分,也是微软公司极力推荐的新一代程序开发语言。WinForm是.Net开发平台中对Windows Form的一种称谓。.Net 为开发WinForm的应用程序提供了丰富的Class Library(类库)。这些WinFrom 类库支持RAD(快速应用程序开发),这些类库被封装在一个名称空间之中,这个名称空间就是System.Windows.Forms。在此名称空间中定义了许多类,在开发基于.Net的GUI应用程序的时候,就是通过继承和扩展这些类才使得我们的程序有着多样的用户界面。本文就试图通过一个最基本的类--Form,来具体说明一下用Visual C#开发WinForm程序的具体过程。
///作用:FileUpLoad 上传大文件使用.net 的FileUpLoad 控件上传文件非常的方便, 在Web.config 中的<System.web>下添加如下的语句
<system.web>
<httpRuntime maxRequestLength="1000000" executionTimeout="45"/>
</system.web>
maxRequestLength 的单位为字节,executionTimeout的单位为秒
//upload code:
Boolean fileOK = false;
String path = Server.MapPath("~/Images/");
if (FileUpload1.HasFile)
{
String fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
}
}
}
if (fileOK)
{
try
{
FileUpload1.PostedFile.SaveAs(path
+ FileUpload1.FileName);
Label1.Text = "File uploaded!";
}
catch (Exception ex)
{
Label1.Text = "File could not be uploaded.";
}
}
else
{
Label1.Text = "Cannot accept files of this type.";
}
<system.web>
<httpRuntime maxRequestLength="1000000" executionTimeout="45"/>
</system.web>
maxRequestLength 的单位为字节,executionTimeout的单位为秒
//upload code:
Boolean fileOK = false;
String path = Server.MapPath("~/Images/");
if (FileUpload1.HasFile)
{
String fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
}
}
}
if (fileOK)
{
try
{
FileUpload1.PostedFile.SaveAs(path
+ FileUpload1.FileName);
Label1.Text = "File uploaded!";
}
catch (Exception ex)
{
Label1.Text = "File could not be uploaded.";
}
}
else
{
Label1.Text = "Cannot accept files of this type.";
}
Tags: Code
幻の小屋
|
软件&技术
|