閲覧総計:&counter();  (本日:&counter(today);  昨日:&counter(yesterday);)

 Ajax Control Toolkitは、日付入力に便利なCalendar Extenderという部品を
提供してくれている。早速使ってみた。 09/08/11
 ASP.NETでのテキストファイルの書込みと読込みの方法を確認した。 09/08/12

 ところが、このCalender Extenderは標準の方法での日本語表示化では、カレンダ
の表示の全てが日本語表示になってくれない。この欠点を補完するする方法が
↓このページに紹介されていたので、対応してみた。
http://devadjust.exblog.jp/7018028/
 .NET Framework2.0からFile.WriteAllText(), File.ReadAllText()メソッド
が提供されテキストファイルのハンドリングが非常に簡単になっている。
 以下に提示したコードは冗長的になっている部分があるが、基本機能を示すサン
プルコードの提示であるので了解頂きたい。 09/08/12

開発環境:VWD2005+AJAX1.0+Toolkit + SQL Server2005
サーバ:ASP.NET2.0+AJAX1.0 + SQL Server

【機能】TextBoxをクリックするとカレンダがポップアップし、日付が簡単に入力できる。
    (カレンダの表示が日本語化されているところが特徴)

【稼動サンプル】
http://www.kuri6005.fscs.jp/4AjaxTr/Toolkit/Calendar03.aspx
#ref(Calendar02.JPG);
http://www.kuri6005.fscs.jp/4AspNet10/TextRW/TextRW.aspx
#ref(textRW01.JPG);

作成時の画面
#ref(Calendar01.JPG);
~

コントロールの設定値
|~コントロール|~プロパティ|~値|~コメント|
|ScriptManager|EnableScriptGlobalization|True|Ajaxツールの表示を日本語に|
|~|EnableScriptLocalization|True|~|
|CalendarExtender|TargetControlID|TextBox1|ターゲットを指定|
|TextBox1|TextMode|MultiLine|複数行表示に設定|

【Calendar03.aspx】

【TextRW.aspx】
 <%@ Page Language="VB" %>
 
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
 <script runat="server">
 
     '参考ページ:テキストファイルの入出力 07/04/18
     'http://migelnanai.blog.so-net.ne.jp/2007-04-18-1
     Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
         'Dim strFile As String = "test01.txt"
         Dim strFile As String = Server.MapPath("test01.txt")
         '入力するテキスト
         Dim strInputText As String = TextBox1.Text
         
         'Shift_JISのファイルに書き込む。
         Dim enc As System.Text.Encoding = System.Text.Encoding.GetEncoding("Shift_JIS")
 
         System.IO.File.WriteAllText(strFile, strInputText, enc)
     End Sub
 
     Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
         'Dim strFile As String = "test01.txt"
         Dim strFile As String = Server.MapPath("test01.txt")
         '入力するテキスト
         Dim strInputText As String = TextBox1.Text
         
         'Shift_JISのファイルに書き込む。
         Dim enc As System.Text.Encoding = System.Text.Encoding.GetEncoding("Shift_JIS")
 
         System.IO.File.AppendAllText(strFile, strInputText, enc)
     End Sub
     
     Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs)
         'Dim strFile As String = "ファイル名"
         Dim strFile As String = Server.MapPath("test01.txt")
 
         'Shift_JISのファイルを読み込む。
         Dim enc As System.Text.Encoding = System.Text.Encoding.GetEncoding("Shift_JIS")
 
         'テキストファイルの中身をすべて読み込む
         Dim strText As String = System.IO.File.ReadAllText(strFile, enc)
         'テキストファイルを配列として行ごとに読み込む
         'Dim strTextLines As String() = System.IO.File.ReadAllLines(strFile, enc)
         Dim strAllText As String = System.IO.File.ReadAllText(strFile, enc)
         
         TextBox1.Text = strAllText
     End Sub
     
     Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs)
         'Dim strFile As String = "test01.txt"
         Dim strFile As String = Server.MapPath("test01.txt")
         '入力するテキスト
         Dim strInputText As String = ""
         TextBox1.Text = ""
         
         'Shift_JISのファイルに書き込む。
         Dim enc As System.Text.Encoding = System.Text.Encoding.GetEncoding("Shift_JIS")
 
         System.IO.File.WriteAllText(strFile, strInputText, enc)
     End Sub
 
 </script>
 
 <html xmlns="http://www.w3.org/1999/xhtml" >
 <head runat="server">
     <title>無題のページ</title>
 </head>
 <body>
     <form id="form1" runat="server">
     <div>
         テキストファイルの書込み・読み出し 09/08/12<br />
         <br />
         【機能】テキストファイルの上書き書込み、追加書込<br />
         み、読み出し、消去を行う。<br />
         <asp:TextBox ID="TextBox1" runat="server" Height="175px" Width="327px" TextMode="MultiLine"></asp:TextBox><br />
         <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="上書き書込み" />
         <asp:Button ID="Button2" runat="server" Text="追加書込み" OnClick="Button2_Click" />
         <asp:Button ID="Button3" runat="server" Text="読出し" OnClick="Button3_Click" />
         <asp:Button ID="Button4" runat="server" Text="消去" OnClick="Button4_Click" /><br />
     </div>
     </form>
 </body>
 </html>


【参考にしたページ】
1.Ajaxカレンダの表示を日本語化する 08/01/19
http://devadjust.exblog.jp/7018028/
1.テキストファイルの入出力 07/04/18
http://migelnanai.blog.so-net.ne.jp/2007-04-18-1

2.JavaScriptコードの埋め込み方法 04/05/21
http://www.atmarkit.co.jp/fdotnet/dotnettips/160regscript/regscript.html
2.テキスト・ファイルの内容を簡単に書き込むには? 07/12/06
http://www.atmarkit.co.jp/fdotnet/dotnettips/680filewriteall/filewriteall.html

【サーバ設置時のハマリポイント】
 txtファイルの書込み・読込みプログラムをサーバに設置した時、最初はうまく
動いてくれなかった。原因は、対象フォルダの「書き込み権限」の許可がされていな
かったからだった。
 皆さん、サーバ対象フォルダの「書き込み権限」の許可設定を忘れないようにしま
しょう。 09/08/12

(設定操作)
 サーバにloginし、「ファイルのフォルダの管理(ファイルマネジャ)」で
対象プログラムを設置したフォルダのWeb Visitorの「書き込み」にチェックを付け、
「Apply」ボタンをクリックし、情報更新を行う。
#ref(textRW02.JPG);


#comment_nospam
#vote(参考になった[0],ふつう[0],参考にならなかった[0])


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS