页面创建记事本并且赋值 页面创建记事本并且赋值! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <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 } }} 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(); 楼主好强,ASP.NET可以调用WINFORM的DLL函数 如梦大哥 这个path是传什么 路劲吗? 太麻烦了,, StreamWriter sw = new StreamWriter(@"C: \Client\tmp.txt"); sw.WriteLine("记事本内容"); sw.Close();刚才找了个简单的 sql中查询时间问题 关于页面传值的问题? 在线等...请各位朋友看下? 为什么TextBox和DropDownList的在浏览器中不一样宽 页面来路问题_________________________ 网站动静结合问题???? 关于两个dropdownlist互相关联的问题,急。 窗体验证的问题,高人帮忙解决一下,谢谢! 求,asp.net揭秘第二版电子版,不知有吗? ASP在windows身份验证模式下如何连接SQL Server2005 showmodaldialog的问题 VB->C# 这两种写法是完全等价的吧? Grid+report在asp.net中怎么使用
<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
}
}
}
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();
如梦大哥 这个path是传什么 路劲吗?
sw.WriteLine("记事本内容");
sw.Close();刚才找了个简单的