asp.net中执行exe应用程序,终极解决方案。
在asp.net中执行应用程序有两种方法:1、调用win32函数ShellExecute。2、用.NET
Framework中的Process类。下面我分别用这两种方法执行Windows中的记事本程序notepad.exe。
新建一个ASP.Net页面Default.aspx,在上面放一个按钮,进入Default.aspx.cs页面填写后台处理程序。
1、调用win32函数ShellExecute。
添加引用using System.Runtime.InteropServices;
声明函数:
[DllImport('shell32.dll')]
private static extern IntPtr ShellExecute(IntPtr hwnd, string
lpOperation, string lpFile, string lpParameters, string
lpDirectory, Int32 nShowCmd);
在按钮的单击事件处理程序中调用前面生明的ShellExecute函数:
ShellExecute(IntPtr.Zero, 'open', 'c:\\windows\\notepad.exe', null,
null, 1);
//文件名可以不加后缀,如'c:\\windows\\notepad'。
程序完成
2、用.NET Framework中的Process类
添加引用using System.Diagnostics;
在按钮的单击事件处理程序中
先安装WPS
然后添加引用安装目录下的etapp.dll
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using System.Collections;
using ET;
namespace ExcelToPdf
{
public partial class Form1 : Form
{
int ifsucess = 0;
int iffail = 0;
int allcount = 0;
int num = 0;
public Form1()
{
InitializeComponent();
先安装office 2007
然后安装office 2007 PDF转换插件SaveAsPDFandXPS.exe(去官网下去)
然后新建项目,引用Microsoft PowerPoint 12.0 Object Library;Microsoft Word
12.0 Object Library;Microsoft Excel 12.0 Object Library
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Word = Microsoft.Office.Interop.Word;
using Excel = Microsoft.Office.Interop.Excel;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Microsoft.Office.Core;
using System.IO;
namespace ExcelToPDFMS
{
public partial class PDF : Form
{
int ifsucess = 0;
int iffail = 0;
private void button4_Click(object sender, EventArgs
e)
{
//设置登录连接的类
DataSet dset = new DataSet();
SAPLogonCtrl.SAPLogonControlClass logon = new
SAPLogonCtrl.SAPLogonControlClass();
//连接参数设置
logon.ApplicationServer = '服务器IP';
logon.Client = '集团号';
logon.Language = 'ZH';
logon.User = 'SAP登录名称';
&nbs
public void test()
{
SAPLogonControlClass connctl = new SAPLogonControlClass();
//下面的参数值根据实际情况赋值
connctl.Client = '集团号';
connctl.Language = 'ZH';
connctl.ApplicationServer = '服务器IP';
connctl.SystemNumber = 00;
connctl.User = 'SAP登录名';
connctl.Password = 'SAP密码';
Connection conn = (Connection)conn
当在一台计算机上并行执行多个 .NET Framework 版本时,映射到 ASP.NET 应用程序的 ASP.NET
ISAPI 版本决定了该应用程序所使用的公共语言运行库版本。ASP.NET IIS 注册工具 (Aspnet_regiis.exe)
使管理员或安装程序可以方便地更新 ASP.NET 应用程序的脚本映射,使其指向与该工具关联的 ASP.NET ISAPI
版本。该工具还可以用于显示所有已安装的 ASP.NET 版本的状态、注册与该工具耦合的 ASP.NET
版本、创建客户端脚本目录,以及执行其他配置操作。
当您尝试调试的计算机上未正确安装 ASP.NET 时,会发生此错误。这可能意味着 ASP.NET 从未安装过,或者
ASP.NET 是在 IIS 之前安装的。
重新安装 ASP.NET
从命令提示窗口中,输入命令。
关于不同版本的ASP.NET IIS的注册:
ASP.NET
1.1.4322
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\aspnet_regiis.exe
ASP.NET
2.0.50727
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.ex
Excel.Application myExcel;
Excel.Workbook myWorkBook;
myExcel = new Excel.Application();
myWorkBook = myExcel.Application.Workbooks.Add(true);
try
{
myWorkBook.SaveCopyAs(fullpath);
myWorkBook.Close(false, null, null);
}
catch (Exception ex)
&n
private void button1_Click(object sender, EventArgs
e)
{
Excel.Application excelkccx = new Excel.ApplicationClass();
Excel._Workbook wb;
Excel._Worksheet ws = null;
wb= excelkccx.Workbooks.Add(true);
string tbname = this.textBox1.Text.Trim();
System.Data.DataTable dt = new
db().getinfo(tbname).Tables[0];
if (ws == null)
{
&nbs
private void button1_Click(object sender, EventArgs
e)
{
Excel.Application excelkccx = new Excel.Application();
excelkccx.Workbooks.Add(true);
string tbname = this.textBox1.Text.Trim();
System.Data.DataTable dt = new
db().getinfo(tbname).Tables[0];
int row = 2;
for (int i = 0; i < dt.Columns.Count;i++)
{
excelkccx.Cells[1, i + 1]
在body里加上topMargin='0' MS_POSITIONING='GridLayout',页面上面的一小块空白就没了