页面创建记事本并且赋值!

解决方案 »

  1.   

     <table width="600px" align="center">
                <tr align="center">
                    <td align="center">创建记事本,并给记事本输入文字</td>
                </tr>
                <tr>
                    <td>
                        <asp:TextBox ID="txtNotepad" runat="server" Height="500px" TextMode="MultiLine" Width="100%"></asp:TextBox></td>
                </tr>
                <tr>
                    <td align="center">
                        <asp:Button ID="btSubmit" runat="server" Text="打开记事本" OnClick="btSubmit_Click" /></td>
                </tr>
            </table>
    代码:
            private string strShow = "";//记事本里面需要显示的内容,默认为空        protected void Page_Load(object sender, EventArgs e)
            {
                if (IsPostBack)
                {
                    strShow = txtNotepad.Text;
                }
            }        #region [ API: 记事本 ]
            /// <summary>
            /// 传递消息给记事本
            /// </summary>
            /// <param name="hWnd"></param>
            /// <param name="Msg"></param>
            /// <param name="wParam"></param>
            /// <param name="lParam"></param>
            /// <returns></returns>
            [System.Runtime.InteropServices.DllImport("user32.dll")]
            public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, string lParam);        /// <summary>
            /// 查找句柄
            /// </summary>
            /// <param name="hwndParent"></param>
            /// <param name="hwndChildAfter"></param>
            /// <param name="lpszClass"></param>
            /// <param name="lpszWindow"></param>
            /// <returns></returns>
            [System.Runtime.InteropServices.DllImport("user32.dll")]
            public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);        /// <summary>
            /// 记事本需要的常量
            /// </summary>
            public const uint WM_SETTEXT = 0x000C;
            #endregion        protected void btSubmit_Click(object sender, EventArgs e)
            {
                #region [ 启动记事本 ]
                System.Diagnostics.Process Proc;            try
                {
                    // 启动记事本
                    Proc = new System.Diagnostics.Process();
                    Proc.StartInfo.FileName = "notepad.exe";//记事本
                    //Proc.StartInfo.FileName = "calc.exe";//计算器
                    Proc.StartInfo.UseShellExecute = false;
                    Proc.StartInfo.RedirectStandardInput = true;
                    Proc.StartInfo.RedirectStandardOutput = true;                Proc.Start();
                }
                catch
                {
                    Proc = null;
                }            #endregion            #region [ 传递数据给记事本 ]            if (Proc != null)
                {
                    // 调用 API, 传递数据
                    while (Proc.MainWindowHandle == IntPtr.Zero)
                    {
                        Proc.Refresh();
                    }                IntPtr vHandle = FindWindowEx(Proc.MainWindowHandle, IntPtr.Zero, "Edit", null);                // 传递数据给记事本
                    SendMessage(vHandle, WM_SETTEXT, 0, strShow);
                }            #endregion
            }
        }
    }
      

  2.   

    System.IO.File.WriteAllBytes(path, bytes);System.IO.FileStream f = new System.IO.FileStream(path, System.IO.FileMode.Create);
    f.Write(Array, offset, count);
    FileStream fsMyfile = new FileStream("test.txt" , FileMode.Create, FileAccess.ReadWrite);   
      StreamWriter swMyfile = new StreamWriter(fsMyfile);
      swMyfile.WriteLine("Hello");  
      swMyfile.Flush();
      

  3.   

    楼主好强,ASP.NET可以调用WINFORM的DLL函数
      

  4.   


    如梦大哥 这个path是传什么  路劲吗?
      

  5.   

    太麻烦了,, StreamWriter sw = new StreamWriter(@"C: \Client\tmp.txt");
                sw.WriteLine("记事本内容");
                sw.Close();刚才找了个简单的