Microsoft and New York Times build great applications called NYTR, this applications provide us to read a news more flexible in screen orientation, anotaion, save and read news offline, archiving, and so many feature there. Microsoft and New York Times want to show the diference of user experience using Smart Client Technology and Windows Presentation Framework.. and you can see and search the demo about that applications. Unfortunately this applications is not shared source.
We build a same application called Kompas Reader Applications, this application is build with same technology (WPF) and have a little bit a same feature J . You can see some screen shoot here
here
So be ready for reading a news online or offline without open your browser.. Big thanks to my teacher and my big bro B. for their unlimited support
Best Regards,
Ridi
One of my new friend ask me about this and i said..you can get it easy in docx document (because it's xml in zip package) using package class in .NET 3.0 but how to read the doc file (word 2003 or before). Well in this case you can do some basic interop with word object through your windows form. First you need to install Word 2003 and it's PIA after that create a library for open the doc file juts like i did
using System;
using System.Collections.Generic;
using System.Text;
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;
using System.Reflection;
namespace Ridilabs.Componet.WordDuplicator
{
public
class
WordContentReader
{
private
string _file;
private
string _content;
private Word.Application _objWord;
private Word.Document _doc;
public
string Content
{
get { return _content; }
set { _content = value; }
}
public WordContentReader(string file)
{
_file = file;
_objWord = new Microsoft.Office.Interop.Word.Application();
}
public
string Open()
{
_objWord.Visible = false; // hide the word
object missing = Missing.Value;
object filename = _file;
// drunk in missing reserved word in C# :D
_doc = _objWord.Documents.Open(ref filename, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing);
// now get the content
Word.Range range = _doc.Content;
_content = range.Text;
return _content;
}
public
void Close()
{
_objWord = null;
_doc = null;
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
}
Now let's do some test in windows form applications. We will display the opened documents into a RichTextBox class
Create one button and one richtextbox and give the event for the button clik like this
private
void btnOpen_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new
OpenFileDialog();
ofd.Filter = "doc files (*.doc)|*.txt|docx files (*.docx)|*.docx" ;
if (ofd.ShowDialog() == DialogResult.OK)
{
objWord = new
WordContentReader(ofd.FileName);
objWord.Open();
rtbContent.Text = objWord.Content;
}
}
Might be it's odd for some people (just like i do), but just like my teacher said it's "coding hore hore" so happy coding with Office
Regards
Ridi F
Yup we want to start the fisrt event of Microsoft Innovation Center UGM. This event will start at 19 February and finish at 21 February 2007. It's about "Magneto" Windows Mobile 5.0. Well we will talk about WM architecture design, .NET compact framework, ASP.NET mobile (mobile web form), Mobile Client Software Factory and of course we talk a litle bit about "CrossBow" Windows Mobile 6.0 that had been launched at 12 February in this year.
The labs seem ready and having no problem, (because it's use XP) but my laptop having a problem (because it's use Vista Business). Windows Mobile team had released the active sync for Vista called Windows Mobile Devices Center/WMDC, yup you might know that Vista is shipped with only basic driver for exploring file not to sync with it. But the WMDC can't connect to emulator using DMA protocol, seems need a "real device" for tomorrow demo (is there anybody want to give me XDA Zinc he8x J )
Ok meet you there..
Best Regards,
Ridi F
Yup it’s XML, just like what Microsoft said about standardization in their open XML format. Standard mean we can generate office 2007 file using code (yumm). Open XML format in Office 2007 is just a zip file with normal compression (you can compare with 2003 file). so you can open it with any Zip manager. Office Open XML File (OOXF for shake of my typing ) Formats is heavily dependent upon relationships. OOXF relationship consist in two relationships First, there are package relationships that define an association between a package and its top-level parts and second there are part relationships that define a parent/child relationship between two parts within the same package. When you open the docx file using your favorite Zip manager tou see that you can generate it on the fly.
How? Well there are many approach you can open zip package using any existing zip library such as J# zip library, .net 2.0 library, third party or .net 3.0 package windows base library after that you can use System.xml to write. Here a sample OOXF file
<?xml version="1.0" encoding="utf-8"?>
<w:document xmlns:w=
"http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:body>
<w:p>
<w:r>
<w:t>Hello INDC</w:t>
</w:r>
</w:p>
</w:body>
</w:document>
My recommendations is to use .NET 3.0 livbrary becuase they aware with OOFX. OK let’s do some noise with our keyboard and visual studio. Let’s create a simple class library that can create a library class like this (don’t forget to add WindowsBase reference
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;
using System.IO.Packaging;
namespace Ridilabs.Component.GenerateDocument
{
public class GenerateDocX
{
public void CreateDocument(string fileName, string content)
{
// tell about the template OOXF
Package pack = Package.Open(fileName, FileMode.Create, FileAccess.ReadWrite);
Uri uri = new Uri(@"/word/document.xml", UriKind.Relative);
string partContentType = @"application/vnd.openxmlformats" +
"-officedocument.wordprocessingml.document.main+xml";
PackagePart part = pack.CreatePart(uri, partContentType);
StreamWriter streamPart = new StreamWriter(part.GetStream(FileMode.Create, FileAccess.Write));
string nsWP = @"http://schemas.openxmlformats.org" +
"/wordprocessingml/2006/main";
// structure in word 2007
XmlDocument xmlPart = new XmlDocument();
XmlElement tagDoc = xmlPart.CreateElement("w:document", nsWP);
xmlPart.AppendChild(tagDoc);
XmlElement tagBody = xmlPart.CreateElement("w:body", nsWP);
tagDoc.AppendChild(tagBody);
XmlElement tagPara = xmlPart.CreateElement("w:p", nsWP);
tagBody.AppendChild(tagPara);
XmlElement tagRun = xmlPart.CreateElement("w:r", nsWP);
tagPara.AppendChild(tagRun);
XmlElement tagText = xmlPart.CreateElement("w:t", nsWP);
tagRun.AppendChild(tagText);
// lets insert some word
XmlNode nodeText = xmlPart.CreateNode(XmlNodeType.Text, "w:t", nsWP);
nodeText.Value = content;
tagText.AppendChild(nodeText);
// save xml
xmlPart.Save(streamPart);
streamPart.Close();
pack.Flush();
// create relationship
string relType = @"http://schemas.openxmlformats.org" +
"/officeDocument/2006/relationships/officeDocument";
pack.CreateRelationship(uri, TargetMode.Internal, relType, "rId1"); // recomended using rId1 like my name :) )
pack.Flush();
pack.Close();
}
}
}
Now do some test
using System;
using System.Collections.Generic;
using System.Text;
using Ridilabs.Component.GenerateDocument;
namespace TestGenerate
{
class Program
{
static void Main(string[] args)
{
GenerateDocX test = new GenerateDocX();
test.CreateDocument("Ridi.docx", "Hello INDC How are you today");
}
}
}
Meet You in another Office technology, Cheer
Ridi Ferdiana