Exemple #1
0
        /// <summary>
        /// Opens a file dialog allowing the user to select a file.
        /// </summary>
        /// <returns>Path to selected file</returns>
        public String SelectFile()
        {
            String path             = "";
            Stream myStream         = null;
            DatabaseFileHandler dfh = new DatabaseFileHandler();

            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
            openFileDialog1.Filter           = "All files (*.*)|*.*";
            openFileDialog1.FilterIndex      = 1;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            path = openFileDialog1.FileName;
                        }
                    }
                }
                catch (Exception)
                {
                    //MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                    MessageBox.Show("Could not read file from disk", "File Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            return(path);
        }
Exemple #2
0
        protected void DeleteFile_Click(object sender, EventArgs e)
        {
            int fileID = Int32.Parse(((LinkButton)sender).CommandArgument.ToString());
            DatabaseFileHandler dfh = new DatabaseFileHandler();

            dfh.DeleteFile(fileID);
            HttpContext.Current.Response.Redirect(Request.RawUrl);
        }
Exemple #3
0
 protected void Upload_Click(object sender, EventArgs e)
 {
     if (Request.Files.Count > 0)
     {
         var file = Request.Files[0];
         if (file != null && file.ContentLength > 0)
         {
             String fileName         = Path.GetFileName(file.FileName);
             DatabaseFileHandler dfh = new DatabaseFileHandler();
             dfh.UploadFile(Int32.Parse(Session["projectID"].ToString()), file.InputStream, fileName);
             Response.Redirect(Request.RawUrl);
         }
     }
 }
Exemple #4
0
 protected void NewProject_Click(object sender, EventArgs e)
 {
     if (projectName.Value.ToString() != "" && projectName.Value.ToString() != null && Request.Files.Count > 0)
     {
         Project p   = new Project();
         String  pID = p.CreateProject(projectName.Value.ToString(), Int32.Parse(Session["uID"].ToString()));
         if (Request.Files.Count > 0)
         {
             var file = Request.Files[0];
             if (file != null && file.ContentLength > 0)
             {
                 String fileName         = Path.GetFileName(file.FileName);
                 DatabaseFileHandler dfh = new DatabaseFileHandler();
                 int     i  = dfh.UploadFile(Int32.Parse(pID), file.InputStream, fileName);
                 Project p1 = new Project();
                 p1.ResearcherSign(Int32.Parse(pID), Session["uID"].ToString());
                 Response.Redirect(Request.RawUrl);
             }
         }
     }
 }
Exemple #5
0
        protected void Download_Click(object sender, EventArgs e)
        {
            string[]            args = ((LinkButton)sender).CommandArgument.ToString().Split('|');
            DatabaseFileHandler dfh  = new DatabaseFileHandler();

            byte[] blob = dfh.GetFile(Int32.Parse(args[0]));
            try
            {
                if (args[1].EndsWith(".xlxs") || args[1].EndsWith(".xls"))
                {
                    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                }
                else
                {
                    Response.ContentType = "application/octet-stream";
                }
                Response.AddHeader("Content-Disposition", "attachment; filename=\"" + args[1] + "\"");
                Response.OutputStream.Write(blob, 0, blob.Length);
                Response.Flush();
            }
            catch (Exception) { }
        }