示例#1
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            // Although I put only one http file control on the aspx page,
            // the following code can handle multiple file controls in a single aspx page.
            HttpFileCollection files = Request.Files;

            foreach (string fileTagName in files)
            {
                HttpPostedFile file = Request.Files[fileTagName];
                if (file.ContentLength > 0)
                {
                    // Due to the limit of the max for a int type, the largest file can be
                    // uploaded is 2147483647, which is very large anyway.
                    int    size     = file.ContentLength;
                    string name     = file.FileName;
                    int    position = name.LastIndexOf("\\");
                    name = name.Substring(position + 1);
                    string contentType = file.ContentType;
                    byte[] fileData    = new byte[size];
                    file.InputStream.Read(fileData, 0, size);
                    int d = Convert.ToInt32(Request.QueryString["id"]);

                    FileUtilities1.SaveFile(name, d, contentType, size, fileData);
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Uploaded');", true);
                }
            }
            int       ad       = Convert.ToInt32(Request.QueryString["id"]);
            DataTable fileList = FileUtilities1.GetFileList(ad);

            gvFiles.DataSource = fileList;
            gvFiles.DataBind();
        }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["user"] == null)
            {
                Response.Redirect("Home.aspx");
            }
            int ad = Convert.ToInt16(Request.QueryString["id"]);

            if (!IsPostBack)
            {
                DataTable fileList = FileUtilities1.GetFileList(ad);
                gvFiles.DataSource = fileList;
                gvFiles.DataBind();
            }

            // Get the file id from the query string


            // Get the file from the database
            DataTable file = FileUtilities1.GetAFile(ad);
            DataRow   row  = file.Rows[0];

            string name        = (string)row["Name"];
            string contentType = (string)row["ContentType"];

            Byte[] data = (Byte[])row["Data"];

            // Send the file to the browser
            Response.AddHeader("Content-type", contentType);
            Response.AddHeader("Content-Disposition", "attachment; filename=" + name);
            Response.BinaryWrite(data);
            Response.Flush();
            Response.End();
        }
示例#3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int ad = Convert.ToInt32(Request.QueryString["id"]);



            string pass = (string)Session["pass"];

            DataTable fileList = FileUtilities1.GetFileList(ad);

            gvFiles.DataSource = fileList;
            gvFiles.DataBind();
        }