private void btnAddFile_Click(object sender, RoutedEventArgs e)
        {
            if (!string.IsNullOrEmpty(txbFilePath.Text) && cbPackageName.SelectedIndex != -1 && cbPackageName.SelectedIndex != 0)
            {
                if (!Directory.Exists(ConfigurationManager.AppSettings["XmlDestination"] + "/" + cbPackageName.SelectedValue.ToString()))  // if it doesn't exist, create
                    Directory.CreateDirectory(ConfigurationManager.AppSettings["XmlDestination"] + "/" + cbPackageName.SelectedValue.ToString());


                if (!Directory.Exists(ConfigurationManager.AppSettings["XmlDestination"] + "/" + cbPackageName.SelectedValue.ToString() + "/Temp/" + cbFileTypes.SelectedValue.ToString()))  // if it doesn't exist, create
                    Directory.CreateDirectory(ConfigurationManager.AppSettings["XmlDestination"] + "/" + cbPackageName.SelectedValue.ToString() + "/Temp/" + cbFileTypes.SelectedValue.ToString());

                File.Copy(txbFilePath.Text, ConfigurationManager.AppSettings["XmlDestination"] + cbPackageName.SelectedValue.ToString() + "\\Temp\\" + cbFileTypes.SelectedValue.ToString() + "\\" + Path.GetFileName(txbFilePath.Text), true);

                Attachment fileAttachment = new Attachment();
                fileAttachment.Type = cbFileTypes.SelectedValue.ToString();
                fileAttachment.Name = Path.GetFileName(txbFilePath.Text);
                fileAttachment.Comments = txbComments.Text;

                if (dsAttachments.Where(n => n.Type == fileAttachment.Type && n.Name == fileAttachment.Name).Count() == 0)
                    dsAttachments.Add(fileAttachment);
                else
                {
                    Attachment existingItem = dsAttachments.Where(n => n.Type == fileAttachment.Type && n.Name == fileAttachment.Name).FirstOrDefault();
                    int fileIndex = dsAttachments.IndexOf(existingItem);

                    dsAttachments.RemoveAt(fileIndex);

                    dsAttachments.Insert(fileIndex, fileAttachment);
                }

                cbFileTypes.SelectedIndex = 0;
                txbFilePath.Text = "";
                txbComments.Text = "";

                RefreshTree();
            }
            else
                MessageBox.Show("File path / Package Name must be entered.");
        }
Ejemplo n.º 2
0
        public static ObservableCollection<Attachment> GetAttachmentListFromXml(IEnumerable<XElement> xmlAttachments)
        {
            ObservableCollection<Attachment> attachmentList = new ObservableCollection<Attachment>();

            foreach(XElement file in xmlAttachments.Elements())
            {
                Attachment attachment = new Attachment();
                attachment.Type = file.Element("Type").Value.ToString();
                attachment.Name = file.Element("Name").Value.ToString();
                attachment.Comments = (file.Element("Comments") == null ? "" : file.Element("Comments").Value.ToString());

                attachmentList.Add(attachment);
            }

            return attachmentList;
        }