Пример #1
0
        public static File createFile(File entry)
        {
            IDictionary<string, object> parameters = new Dictionary<string, object>();
            parameters.Add("@id", entry.ID);
            parameters.Add("@filename", entry.FileName);
            parameters.Add("@creationDate", entry.CreationDate);
            parameters.Add("@deletionDate", entry.DeletionDate);
            parameters.Add("@mimeType", entry.MimeType);
            parameters.Add("@fileSize", entry.FileSize);

            try
            {
                DataTable dt = SQLHelper.ExecuteDataTable(checkFreeIDStatement, parameters);

                while (dt.Rows.Count > 0)
                {
                    entry.CreateNewID();
                    parameters["@id"] = entry.ID;
                    dt = SQLHelper.ExecuteDataTable(checkFreeIDStatement, parameters);
                }

                SQLHelper.ExecuteDataTable(createFileStatement, parameters);
            }
            catch (Exception)
            {
                return null;
            }
            return entry;
        }
Пример #2
0
        /// <summary>
        /// Konvertiert eine DataRow zu einem NewsPost
        /// </summary>
        private static File convertToFile(DataRow dr)
        {
            File entry = new File();

            if (!dr["id"].Equals(DBNull.Value)) entry.ID = (int)dr["id"];
            if (!dr["filename"].Equals(DBNull.Value)) entry.FileName = (String)dr["filename"];
            if (!dr["mimeType"].Equals(DBNull.Value)) entry.MimeType = (String)dr["mimeType"];
            if (!dr["fileSize"].Equals(DBNull.Value)) entry.FileSize = (Int64)dr["fileSize"];
            if (!dr["creationDate"].Equals(DBNull.Value)) entry.CreationDate = (DateTime)dr["creationDate"];
            if (!dr["deletionDate"].Equals(DBNull.Value)) entry.DeletionDate = (DateTime)dr["deletionDate"];
            return entry;
        }
Пример #3
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            if (upFile.PostedFile != null && upFile.PostedFile.ContentLength > 0)
            {
                String fileName = upFile.PostedFile.FileName;
                fileName = fileName.Replace(' ', '_').Replace("ß", "ss").Replace("ü", "ue").Replace("ö", "oe").Replace("ä", "ae");
                String SaveLoc = Server.MapPath("clipboard") + "\\" + fileName;

                try
                {
                    if (!String.IsNullOrWhiteSpace(_UploadPassword) && !tbUploadPassword.Text.Equals(_UploadPassword))
                    {
                        throw new UnauthorizedAccessException("Incorrect upload password");
                    }

                    upFile.PostedFile.SaveAs(SaveLoc);
                    DateTime? deletionDate = null;

                    switch (Convert.ToInt32(ddlDeleteAfter.SelectedValue))
                    {
                        case 1:
                            // Delete after 30 Minutes
                            deletionDate = DateTime.Now.AddMinutes(30);
                            break;
                        case 2:
                            // Delete after 6 hours
                            deletionDate = DateTime.Now.AddHours(6);
                            break;
                        case 3:
                            // Delete after 1 day
                            deletionDate = DateTime.Now.AddDays(1);
                            break;
                        case 4:
                            // Delete after 1 week
                            deletionDate = DateTime.Now.AddDays(7);
                            break;
                        case 5:
                            // Delete after 1 month
                            deletionDate = DateTime.Now.AddMonths(1);
                            break;
                        case 6:
                            // Never delete
                            break;
                    }

                    File importedFile = new File(fileName, upFile.PostedFile.ContentType, upFile.PostedFile.ContentLength, deletionDate);
                    int fileID = FileManager.createFile(importedFile).ID;
                    mvMain.SetActiveView(viewResult);
                    tbDirectLink.Text = "http://clipboard.bolvin.de/clipboard/" + fileName;
                    tbPageLink.Text = "http://clipboard.bolvin.de/file.aspx?id=" + fileID;
                    form1.Attributes.Add("class", "well form-horizontal");
                }
                catch (Exception ex)
                {

                }
            }
        }