第一次写WEBFORM,请教
1、如何打开类似一个opendialog的东西;
2、数据如何传输到数据库。

解决方案 »

  1.   

    1、如何打开类似一个opendialog的东西;  你可以直接使用html 控件 input(file)2 数据 传到 数据库 没有什么特别的 和 传统的 步骤 一样 
      

  2.   

    asp.net里有上传控件,直接用就是了。
      

  3.   

    拖一个叫FileUpload的控件.(vs工具箱里就有.)然后参考下面代码bool fileOK = false;
            string path = Server.MapPath("~/UploadedImages/");
            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.";
            }
      

  4.   

    两种方法: 一种是楼上的 用html的input(file)控件
    还有一种 可以用asp.net的相关控件 asp:FileUpload
    然后在 提交表单的处理事件中(例如Button点击事件)中如下处理:
    string msg = "";
            try
            {
                if (FileUpload1.PostedFile.FileName == "")
                {
                    msg = "请选择文件! ";
                }
                else
                {
                    //这里主要是处理文件名称 类型之类的
                    string filepath = FileUpload1.PostedFile.FileName;
                    string filename = filepath.Substring(filepath.LastIndexOf("\\") + 1);
                    //这里设置文件的保存路径 
                    string serverpath = Server.MapPath("upload/")+filename; 
                    //上传(保存文件)
                      FileUpload1.PostedFile.SaveAs(serverpath);
                    msg = "上传成功! ";
                }
            }
            catch (Exception ex)
            {
                msg = "上传发生错误!原因是: " + ex.ToString();
            }
    Response.Write(msg);至于数据...看你自己想保存文件名还是完整路径 直接赋值 写入数据库就OK~!
    O(∩_∩)O~
      

  5.   

    我是不想拖那个控件出来,那个控件很难看,可以借助其他办法吗?刚才上网找了下
    用script可以实现,一时手快关掉了没留意
      

  6.   

    1:在JSP界面中写:<%@ page contentType="text/html;charset=gb2312"%>
        <%@ page import="com.jspsmart.upload.*" %>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head><body leftmargin="0" topmargin="0" bgcolor="#ffffff">
    <form action="ss.jsp" method="post" name="form1" enctype="multipart/form-data">
        <input name="FileName" type="FILE" size="30">
        <input type="submit" name="Submit" value="上传" >
      </form>
    </body>
    </html><%@ page contentType="text/html;charset=gb2312"%>
        <%@ page import="com.jspsmart.upload.*" %>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    </head><body leftmargin="0" topmargin="0" bgcolor="#ffffff">
    <form action="ss.jsp" method="post" name="form1" enctype="multipart/form-data">
        <input name="FileName" type="FILE" size="30">
        <input type="submit" name="Submit" value="上传" >
      </form>
    </body>
    </html>2:在SS.jsp中写:
    <%@ page language="java" contentType="text/html; charset=GB18030"
        pageEncoding="GB18030"%>    <%@ page import="com.jspsmart.upload.*" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
    <title>Insert title here</title>
    </head>
    <%SmartUpload myupload=new SmartUpload();
    myupload.initialize(pageContext);
    myupload.upload();
    File file=myupload.getFiles().getFile(0);
    String filename=file.getFileName();
    file.saveAs("/file/"+filename,myupload.SAVE_VIRTUAL);
    out.print("文件上传成功!");
     %>
    <body></body>
    </html>
    注意:要引入smartupload.jar包。