drag and drop office 2007 visual c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sarabonn
    New Member
    • Nov 2008
    • 69

    drag and drop office 2007 visual c#

    hallo everyone,

    Actually i know how to drag and drop text file into WPF and read it but i need to drag and drop office 2007 file and extract the file and the xml file in it.

    This is the code i have to drag and drop and read a text file.

    Code:
    private void Form1_Load(object sender, EventArgs e)
    {
        this.AllowDrop = true;
        this.DragEnter += Form1_DragEnter;
        this.DragDrop += Form1_DragDrop;
    }
    private void Form1_DragEnter(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent(DataFormats.FileDrop))
        {
            e.Effect = DragDropEffects.Copy;
        }
        else
        {
            e.Effect = DragDropEffects.None;
        }
    }
     
    private void Form1_DragDrop(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent(DataFormats.FileDrop))
        {
            string[] filePaths = (string[])(e.Data.GetData(DataFormats.FileDrop));
            foreach (string fileLoc in filePaths)
            {
                // Code to read the contents of the text file
                if (File.Exists(fileLoc))
                {
                    using (TextReader tr = new StreamReader(fileLoc))
                    {
                        MessageBox.Show(tr.ReadToEnd());
                    }
                }
     
            }
        }
    }
    I also have the code to unpack the office file and read the xml file.
    Code:
    Package pack = Package.Open(strFilename, FileMode.Open, FileAccess.ReadWrite);
    Uri uri = new Uri("/docProps/cwe-context.xml", UriKind.Relative);
    PackagePart packPart = pack.GetPart(uri);
    XmlDataDocument xdoc = new XmlDataDocument();
    xdoc.Load(packPart.GetStream(FileMode.Open));
    XmlNodeList doc = xdoc.GetElementsByTagName("sioc:Item");
    .

    any idea ?..


    Thank you.
    Last edited by Frinavale; Feb 4 '09, 05:41 PM. Reason: Removed formatting tags that aren't working
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    Well, if you know the code to accept a dropped file, and you know the code to read the XML from an office file...what more do you need? Just use them together.

    Comment

    • sarabonn
      New Member
      • Nov 2008
      • 69

      #3
      hi insertalias,

      Actually i can accept the txt file and i could read it but when i drop the office file in it, i couldn't upack it and read the xml file in it with the code i have. So is there any mistake in my code or i have change something else ?..

      Thank you.

      Comment

      • sarabonn
        New Member
        • Nov 2008
        • 69

        #4
        Originally posted by insertAlias
        Well, if you know the code to accept a dropped file, and you know the code to read the XML from an office file...what more do you need? Just use them together.
        hi insertalias,

        Actually i can accept the txt file and i could read it but when i drop the office file in it, i couldn't upack it and read the xml file in it with the code i have. So is there any mistake in my code or i have change something else ?..

        Thank you.

        Comment

        Working...