示例#1
0
        public ActionResult Download(int id)
        {
            UpDownProcess.UpDownProcess Download = new UpDownProcess.UpDownProcess();
            Hashtable H = Download.Download(ConnectString, id);

            if (H != null)
            {
                TempData["AlertMessage"] = "開始下載";
            }
            else
            {
                TempData["AlertMessage"] = "下載失敗";
            }

            Response.Clear();
            Response.Buffer  = true;
            Response.Charset = "";
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.ContentType = H["contentType"].ToString();
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + H["fileName"].ToString());
            Response.BinaryWrite((byte[])H["bytes"]);
            Response.Flush();
            Response.End();
            return(RedirectToAction("Index"));
        }
示例#2
0
 public ActionResult Upload(HttpPostedFileBase file)
 {
     UpDownProcess.UpDownProcess Upload = new UpDownProcess.UpDownProcess();
     if (Upload.Upload(ConnectString, file))
     {
         TempData["Message"] = "上傳成功 !";
     }
     else
     {
         TempData["AlertMessage"] = "Defect !";
     }
     return(RedirectToAction("Index"));
 }
示例#3
0
        protected void DownloadFile_Click(object sender, EventArgs e)
        {
            //string GUID = (sender as LinkButton).CommandArgument;
            UpDownProcess.UpDownProcess Download = new UpDownProcess.UpDownProcess();
            Hashtable H = Download.Download(ConnectString, Convert.ToInt16(txtFileId.Text));

            Response.Clear();
            Response.Buffer  = true;
            Response.Charset = "";
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.ContentType = H["contentType"].ToString();
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + H["fileName"].ToString());
            Response.BinaryWrite((byte[])H["bytes"]);
            Response.Flush();
            Response.End();
        }
示例#4
0
        protected void Upload_Click(object sender, EventArgs e)
        {
            //seek

            /*
             * connect.Open();
             * LSTR_SQL.Append("select * from  operas");
             * pars.Add(new SqlParameter("Name", "value"));
             * adapter = new SqlDataAdapter(LSTR_SQL.ToString(), connect);
             * adapter.Fill(tb);
             */


            try
            {
                /*
                 * if (File.PostedFile.ContentLength <= 0)
                 * {
                 *  lblErrMsg.Text = "請指定欲上傳的檔案路徑 \r\n";
                 *  return;
                 * }
                 * if (!File.FileName.EndsWith(".pdf"))
                 * {
                 *  lblErrMsg.Text += "請上傳pdf檔 \r\n";
                 *  return;
                 * }
                 */

                //add
                //connect.Open();
                //LSTR_SQL.Append("insert into FileTB (FileName)");
                //LSTR_SQL.Append("values('test')");
                //transaction = connect.BeginTransaction();
                //command = new SqlCommand(LSTR_SQL.ToString(), connect, transaction);
                //int result = command.ExecuteNonQuery();
                //transaction.Commit();



                //upload
                UpDownProcess.UpDownProcess Upload = new UpDownProcess.UpDownProcess();
                if (Upload.Upload(ConnectString, File.PostedFile))
                {
                    lblErrMsg.Text = "上傳成功";
                    SetGV();
                }
                else
                {
                    lblErrMsg.Text = "上傳失敗";
                }
            }
            catch (Exception)
            {
                transaction.Rollback();
                throw;
            }
            finally
            {
                command.Dispose();
                connect.Close();
            }
        }