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.
I also have the code to unpack the office file and read the xml file.
.
any idea ?..
Thank you.
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());
}
}
}
}
}
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.
Comment