.Net 技術のまわりを注目するブログです、もちろん他の個人趣味もあります^^

2010年5月16日日曜日

RTFフォーマットへ出力

C# でRTFフォーマットリッチテキストファイルへテキストを出力するサンプル

private void DrawImage(string title, string filePath)
{
this.richTextBox1.AppendText(title);

//Bitmap bitmap = new Bitmap(lstrFile,);
Image image = Image.FromFile(filePath);
Bitmap bitmap = new Bitmap(image, 500, 500);
Clipboard.SetDataObject(bitmap);
//Clipboard.SetImage(bitmap);

// Get the format for the object type.
DataFormats.Format myFormat = DataFormats.GetFormat(DataFormats.Bitmap);
// After verifying that the data can be pasted, paste
if (this.richTextBox1.CanPaste(myFormat))
{
this.richTextBox1.Paste(myFormat);
}
else
{
MessageBox.Show("The data format that you attempted site is not supportedby this control.");
}

this.richTextBox1.AppendText("\r\n--------------------------------\r\n");

this.richTextBox1.SaveFile(@"C:\temp\richText.rtf", RichTextBoxStreamType.RichText);
}

2010年5月14日金曜日

ASP.NET のイベント発生順序

ASP.NET のイベント発生順序
参考URL:
http://note.miyabis.jp/article/33503965.html
抜粋:
すごく詳しいです^^;

HttpModule を利用して、ページのPreInitイベントを統合する
参考URL:
http://www.martinwilley.com/net/code/PreInitModule.html
抜粋:
HttpApplicationのPreRequestHandlerExecuteイベントを利用する

ネットワーク通信データの監視

C# でPCの通信データを監視するサンプルいくつメモしました。

A Network Sniffer in C#
http://www.codeproject.com/KB/IP/CSNetworkSniffer.aspx

Simple Network Sniffer - Open Source - C#
http://www.digigrupp.com/sniffer/

Packet Sniffer in C#
http://www.c-sharpcorner.com/UploadFile/fyratkocak/PacketSniffer12032005034955AM/PacketSniffer.aspx

Examples of the Packet Sniffer SDK using
http://www.microolap.com/products/network/pssdk/examples.php

Network Sniffer and Connection Analyzer
http://www.codeproject.com/KB/IP/hssniffer.aspx

2010年5月13日木曜日

WordをHTMLへ変換その2

Office Word フォーマットでドキュメントをHTMLへ変換するメモ

Word to HTML Converter using ASP.Net 2.0 and Microsoft 11.0 object Library

http://www.c-sharpcorner.com/UploadFile/munnamax/WordToHtml03252007065157AM/WordToHtml.aspx

Cleaning Word's Nasty HTML

http://www.codinghorror.com/blog/archives/000485.html

WordをHTMLへ変換

C# で Office Word フォーマットでドキュメントをHTMLへ変換します。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

方法1:
private void ConvertFileWordToHtml(string WordFilePath)
{
try
{
//Word ファイル・HTMLの生成先のファイルを指定
object Source = WordFilePath;
string SaveHtmlPath = WordFilePath.Substring(0, WordFilePath.Length - 4) + "html";
object Target = SaveHtmlPath;

//ReadonlyでWordを開く
object Unknown = Type.Missing;
object readOnly = true;
object visible = false;


Microsoft.Office.Interop.Word.Application newApp = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document doc = newApp.Documents.Open(ref Source, ref Unknown,
ref readOnly, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref visible, ref Unknown, ref Unknown, ref Unknown, ref Unknown);

// HTMLへ保存
Type docType = doc.GetType();
object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML;
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
null, doc, new object[] { Target, format,Unknown,Unknown,Unknown,Unknown,Unknown,
Unknown,Unknown,Unknown,Unknown,Unknown,Unknown,Unknown,Unknown,Unknown });
// doc.SaveAs(ref Target, ref format,
// ref Unknown, ref Unknown, ref Unknown,
// ref Unknown, ref Unknown, ref Unknown,
// ref Unknown, ref Unknown, ref Unknown,
// ref Unknown, ref Unknown, ref Unknown,
// ref Unknown, ref Unknown);


// クローズ
doc.Close(ref Unknown, ref Unknown, ref Unknown);
newApp.Quit(ref Unknown, ref Unknown, ref Unknown);
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show(e.Message);
}
}


方法2:
protected void ConvertToHtml(string docPath,string htmlPath)
{
Word.Application app=new Word.Application();
app.Visible=false;
Object o=Missing.Value;
object docFile=docPath;
_Document doc=app.Documents.Open(ref docFile,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o);
object fileName=htmlPath;
object format=8;//Html
doc.SaveAs(ref fileName,ref format,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o);
object t=true;
app.Quit(ref t,ref o,ref o);
}