Ejemplo n.º 1
0
        public List <string> SaveExternalFile(List <IFormFile> file, string FolderName)
        {
            if (!Directory.Exists(Path.Combine(_objhostingEnvironment.WebRootPath, "ExternalDoc")))
            {
                Directory.CreateDirectory(Path.Combine(_objhostingEnvironment.WebRootPath, "ExternalDoc"));
            }
            string strPathName = Path.Combine(_objhostingEnvironment.WebRootPath, "ExternalDoc", FolderName);

            if (!Directory.Exists(strPathName))
            {
                Directory.CreateDirectory(strPathName);
            }
            List <string> _ltFilePath = new List <string>();

            if (file.Count > 0)
            {
                int i = 1;
                foreach (IFormFile Attachment in file)
                {
                    string FilePath    = Path.Combine("ExternalDoc", FolderName, Attachment.FileName);
                    var    strfilepath = Path.Combine(strPathName, Attachment.FileName);
                    using (var fileStream = new FileStream(strfilepath, FileMode.Create))
                    {
                        Attachment.CopyTo(fileStream);
                    }
                    _ltFilePath.Add(FilePath);
                    i = i + 1;
                }
            }
            return(_ltFilePath);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create(int id, CaseAttachmentCreateViewModel model)
        {
            if (id == null)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                string uniqueFileName = null;
                if (model.Attachments != null && model.Attachments.Count > 0)
                {
                    string uFolder = Path.Combine(hostingEnvironment.WebRootPath, "Attachments");
                    //if (!Directory.Exists(uFolder))
                    //{
                    //    Directory.CreateDirectory(uFolder);
                    //}

                    foreach (IFormFile Attachment in model.Attachments)
                    {
                        string uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "Attachments");
                        uniqueFileName = Guid.NewGuid().ToString() + "_" + Attachment.FileName;
                        //uniqueFileName = Attachment.FileName;
                        string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                        // Use CopyTo() method provided by IFormFile interface to
                        // copy the file to wwwroot/images folder
                        FileStream file_stream = new FileStream(filePath, FileMode.Create, FileAccess.Write);
                        Attachment.CopyTo(file_stream);
                        file_stream.Close();
                        file_stream.Dispose();
                        CaseAttachment newAttachment = new CaseAttachment
                        {
                            LocalUserID = User.Identity.Name,
                            CaseID      = id,
                            // Store the file name in PhotoPath property of the employee object
                            // which gets saved to the Employees database table
                            FilePath = uniqueFileName,
                            FileName = Attachment.FileName
                        };
                        _context.Add(newAttachment);
                    }

                    await _context.SaveChangesAsync();
                }
                int cid = id;
                return(RedirectToAction("Details", "Cases", new { id = cid }));
            }
            ViewData["CaseID"] = new SelectList(_context.Case, "CaseID", "CaseID", model.CaseID);
            //ViewData["LocalUserID"] = new SelectList(_context.LocalUser, "LocalUserID", "LocalUserID", caseAttachment.LocalUserID);
            return(View());
        }
Ejemplo n.º 3
0
        private void EditSelectedItem()
        {
            ListView.SelectedListViewItemCollection items = AttachmentsListView.SelectedItems;
            if (items.Count > 1)
            {
                MessageBox.Show("You can only edit one item at the same time.");
                return;
            }

            ObjectListViewItem lvi = items[0] as ObjectListViewItem;
            Attachment         underlyingObject = lvi?.UnderlyingObject as Attachment;

            if (underlyingObject != null)
            {
                Attachment         copy = underlyingObject.Copy();
                EditAttachmentForm form = new EditAttachmentForm(copy);
                if (form.ShowDialog() == DialogResult.OK)
                {
                    copy.CopyTo(underlyingObject);
                    lvi.SubItems[0].Text = underlyingObject.Name;
                }
            }
        }