Beispiel #1
0
        public void ShowDownload(entities.File file)
        {
            if (file == null)
            {
                throw new Exception("Archivo no encontrado en la base de datos.");
            }
            var            data = file.FileChunks;
            SaveFileDialog s    = new SaveFileDialog();

            s.FileName = SelectedFile;
            s.Filter   = "Todos los archivos (*.*)|*.*";
            if (s.ShowDialog(Form.ActiveForm) == DialogResult.Cancel)
            {
                return;
            }
            var path = s.FileName;

            if (File.Exists(path))
            {
                File.Delete(path);
            }
            using (FileStream w = new FileStream(path, FileMode.Append))
            {
                foreach (var chunk in data)
                {
                    w.Write(chunk.Content, 0, chunk.Content.Length);
                }
                w.Close();
            }
            var argument = "/select, \"" + path + "\"";

            Process.Start("explorer.exe", argument);
        }
        protected override void OnSubmit()
        {
            if (Validate() == false)
            {
                return;
            }

            current.Caption = txtCaption.Text.Trim();
            if (uFile.FileDeleted)
            {
                current.File = null;
            }
            if (uFile.FileAdded)
            {
                current.FileAdded = true;
                var           name = uFile.SelectedFile;
                entities.File file = null;
                file      = new entities.File();
                file.Name = Path.GetFileName(name);
                file.CreateChunks(name);
                if (name.EndsWith(".pdf"))
                {
                    file.Type  = "application/pdf";
                    file.Pages = GetPages(name);
                }
                current.File = file;
            }
            else
            {
                current.FileAdded = false;
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }