public static void AddScript(this HtmlDocument htmlDocument, string javaScript)
{
HtmlElement head = htmlDocument.GetElementsByTagName("head")[0];
HtmlElement scriptElement = htmlDocument.CreateElement("script");
IHTMLScriptElement element = (IHTMLScriptElement)scriptElement.DomElement;
element.text = javaScript;
head.AppendChild(scriptElement);
}
public static void AddCSS(this HtmlDocument htmlDocument, string cssFileName)
{
IHTMLDocument2 currentDocument = (IHTMLDocument2)htmlDocument.DomDocument;
int length = currentDocument.styleSheets.length;
IHTMLStyleSheet styleSheet = currentDocument.createStyleSheet(@"", length + 1);
using (TextReader reader = new StreamReader(cssFileName))
{
styleSheet.cssText = reader.ReadToEnd();
}
}
public static void DoPostBack(this HtmlDocument document)
{
document.InvokeScript("__doPostBack");
}
public static void DoPostBack(this HtmlDocument document, string eventTarget, string eventArgument)
{
document.InvokeScript("__doPostBack", new object[] { eventTarget, eventArgument });
}
public static HtmlElement GetElementByTitle(this HtmlDocument document, string title)
{
return (from x in document.All.Cast<HtmlElement>()
where x.GetAttribute("title") == title
select x).SingleOrDefault();
}
html etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
html etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
14 Ekim 2011 Cuma
9 Kasım 2010 Salı
Word Formatını html,rtf,txt,xml formatlarına çeviren Class
Aklıma geldi nasıl olur diye bir class yazayım dedim küçük bir araştırma ile şöyle birşey yazdım.
Öncelikle Class Library Yaratıyoruz
Sonra Referans ekleme işlemlerinden COM tabına gelip
Oradan Microsoft.Office.Interop.Word Component ını seçiyoruz.
public void WordFileTo(string originalFile, object SavePath, string SaveFile, string FileTo)
{
try
{
if (SaveFile == "")
{
return;
}
if (originalFile.Trim() != "" && SavePath.ToString().Trim() != "")
{
Microsoft.Office.Interop.Word.ApplicationClass WordApp = new
Microsoft.Office.Interop.Word.ApplicationClass();
Microsoft.Office.Interop.Word.Document WordDoc = new
Microsoft.Office.Interop.Word.Document();
object DocNoParam = Type.Missing;
object DocFileName = originalFile;
object DocReadOnly = false;
object DocVisible = false;
object SaveToFormat = "";
// Dosya yolunu belirttikten sonra word dökümanımızı açıyoruz
WordDoc = WordApp.Documents.Open(ref DocFileName, ref DocNoParam, ref DocReadOnly,
ref DocNoParam, ref DocNoParam, ref DocNoParam, ref DocNoParam,
ref DocNoParam, ref DocNoParam, ref DocNoParam, ref DocVisible,
ref DocNoParam, ref DocNoParam, ref DocNoParam, ref DocNoParam,
ref DocNoParam);
WordDoc.Activate();
if (FileTo == "html")
{
SaveToFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML;
SavePath = SavePath + SaveFile + ".html";
}
if (FileTo == "rtf")
{
SaveToFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatRTF;
SavePath = SavePath + SaveFile + ".rtf";
}
if (FileTo == "txt")
{
SaveToFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatText;
SavePath = SavePath + SaveFile + ".txt";
}
if (FileTo == "xml")
{
SaveToFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatXML;
SavePath = SavePath + SaveFile + ".xml";
}
//Belirtilen yol ve formata göre dosyayı kayıt ediyoruz.
WordDoc.SaveAs(ref SavePath, ref SaveToFormat, ref DocNoParam, ref DocNoParam, ref
DocNoParam, ref DocNoParam, ref DocNoParam, ref DocNoParam, ref
DocNoParam, ref DocNoParam, ref DocNoParam, ref DocNoParam, ref DocNoParam, ref DocNoParam, ref DocNoParam, ref DocNoParam);
// Orjinal dosyaya herhangi bir değişiklik yapmak istemiyorsak
object SaveChanges = false;
WordApp.Quit(ref SaveChanges, ref DocNoParam, ref DocNoParam);
}
else
{ return; }
}
catch (Exception)
{
return;
}
}
Kaydol:
Kayıtlar (Atom)