| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 457 人关注过本帖
标题:C#File控件问题
取消只看楼主 加入收藏
mijia
Rank: 2
等 级:论坛游民
帖 子:55
专家分:86
注 册:2010-5-13
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:1 
C#File控件问题
<%@ Page Language="C#" AutoEventWireup="true" %>
<script runat="server">
    void Button_Click(object sender, EventArgs e)
    {
        HtmlInputFile file = (HtmlInputFile)place.FindControl("Filel");
        if (Text1.Value == "")
        {
            Span1.InnerHtml = "Error:You must enter a file name.";
            return;
        }
        if (file.PostedFile.ContentLength > 0)
        {
            try
            {
                file.PostedFile.SaveAs("H:\\ASP\\" + Text1.Value);
                Span1.InnerHtml = "File uploaded successfully to" +
                    "<b>H:\\Asp\\" + Text1.Value + "</b> on the web server.";
            }
            catch (Exception exc)
            {
                Span1.InnerHtml = "Error saving flie <b>H:\\ASP\\" +
                    Text1.Value + "</b><br>" + exc.ToString() + ".";     
            }
        }
    }
    void page_Load(object sender, EventArgs e)
    {
        HtmlInputFile file = new HtmlInputFile();
        file.ID = "File";
        place.Controls.Clear();
        place.Controls.Add(file);
    }
   
</script>



<html xmlns="http://www. >
<head>
    <title>HtmlInputFile Constructor Example</title>
</head>
<body>
     <div>HtmlInputFile Constructo Exampler</div>
    <form enctype="multipart/form-data" runat="server">//“form”缺少必需的属性“action”但我不懂在那里加
    Specify the file to upload:
    <asp:placeHolder ID ="place" runat ="server"/>
    <p>
    Save as file name(no path):
    <input id ="Text1"
    type="Text"
    runat="server" />
    </p>
    <p>
    <span id ="Span1"
    style="font :8pt verdana;"
    runat="server"/>
    </p>
    <p>
    <input type ="button"
    id ="Button1"
    value="Upload"
    onserverclick="Button_Click"
    runat="server"/>
    </p>
    </form>
</body>
</html>
能运行
搜索更多相关主题的帖子: 控件 File 
2010-05-24 18:36
mijia
Rank: 2
等 级:论坛游民
帖 子:55
专家分:86
注 册:2010-5-13
收藏
得分:0 
我是用来编写的!不直接用File控件   :Input(File)上传控件
2010-05-25 13:33
快速回复:C#File控件问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017310 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved