發表文章

[轉貼] asp.net 執行Server上的EXE執行檔

   ********************************************************************************** asp.net_執行Server上的EXE執行檔 依照前篇的敘述,第二個要處理的問題是,如何利用asp.net呼叫Server上的exe執行。 如果查網路資料,會查到很多一模一樣的文章,基本上有兩種方式: 1. 利用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); 程式碼: string Dir = page.Server.MapPath("~/"); string CmdStr = Dir + "geoidint.exe"; ShellExecute(IntPtr.Zero, "open", CmdStr, "-I" + Dir + "input.txt -G" + Dir + "output.txt", null, 1); 比較需要注意的地方是,如果你跟我一樣需要傳入參數,就在ShellExecute的第四個參數傳入;又如果傳入的參數是檔案路徑,就要看你所執行的EXE檔是怎麼抓的,像我必須傳入完整路徑,所以參數的部分採組合字串的方式。 2. 利用System.Diagnostics.Process來處理。 引用: using System.Diagnostics; 程式碼: Process process = new Process(); process.StartInfo.FileName = Dir + "geoidint.exe"; process.StartInfo.Arguments = "-I...

ASP.NET 在 SERVER 端動態執行呼叫 javascript 語法

  1.先準備一個網頁         <asp:Button ID="btn1" runat="server" Text="測試" onclick="btn1_Click" /> ********************************************************************************************** 程式         protected void btn1_Click(object sender, EventArgs e)         {             //在 SERVER 端動態執行呼叫 javascript 語法             ScriptManager.RegisterStartupScript(btn1, this.GetType(), "funcTitle", "alert('test');", true);         }

[轉貼] ASP.NET傳遞參數給Crystal Report做Export或Print的動作

圖片
近有網友提到此問題...小弟就做一個demo範例分享給大家呀.. 首先準備一個crystal report檔( CrystalReport.rpt ),內容如下: 在 欄位總管 新增一個參數,如下所示: 接下來就是程式碼 asp.net(C#) ReportView.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="ReportView.aspx.cs" Inherits="ReportView" %> <%@ Register Assembly="CrystalDecisions.Web, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>ReportView</title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="txbLogo" runat="server"></asp:TextBox> ...

[轉貼] ASP.NET 使用 Session 資料時不會再自動消失

圖片
  我們在 ASP.NET 網站使用 Session 時,常常因為 web.config 修改或更新 Bin\ 目錄下的 dll 而導致 Session 消失,Session 常常消失也挺惱人的,不是導致突然被自動登出,就是發生非預期的 Exception ... 等。 ( 有時候因為主機安裝防毒軟體也會造成 Session 資料無故消失,因為這些防毒軟體可能會誤判某檔案、某記憶體含有病毒資訊 ) 這個時候我們可以將 Session 預設的模式 ( InProc ) 改成 StateServer 模式,但此時必須確認本機的 ASP.NET 狀態服務 是啟動的狀態! 請到 控制台 > 系統管理工具 > "服務" 找到 "ASP.NET 狀態服務" 或 "ASP.NET State Service" 此服務預設是屬於「停用」的狀態,請先切換到「自動」再按下「套用」再直接按「啟動」按鈕即可。 接者你可以到你的 ASP.NET 網站設定 web.config 組態檔,設定如下: <configuration>   <system.web>     <sessionState mode="StateServer"       stateConnectionString="tcpip=localhost:42424"       cookieless="false"       timeout="20"/>   </system.web> </configuration> 這樣就可以將 Session 的資料存到本機的 ASP.NET 狀態服務去了,也不會無故 Session 自動消失了。 除了這個方法外,ASP.NET 還可以用 SQL Server 儲存 Session 資料,至於設定的方法可以參考 MSDN 網頁,網址如下: HOW TO:設定 SQL Server 以儲存 ASP.NET 工作階段狀態 http://support.microsoft.com/kb/31760...

[轉貼] 利用Web Service上傳檔案,整合WebFrom與WinForm

圖片
  出處: http://www.dotblogs.com.tw/puma/archive/2009/01/06/6660.aspx 今天就寫一篇簡單的 Web Service 上傳檔案,並且整合在 WebFrom 與 WinForm 使用者介面 首先要準備一支Web Service(上傳檔案用,WebForm或WinForm都會call這支) 接下來準備WebForm與WinForm的UI介面來上傳檔案 Web Service Fileupload.asmx <%@ WebService Language="C#" CodeBehind="~/App_Code/Fileupload.cs" Class="Fileupload" %> Fileupload.cs using System; using System.Web; using System.Collections; using System.Web.Services; using System.Web.Services.Protocols; using System.IO; /// <summary> /// Fileupload 的摘要描述 /// </summary> [WebService(Namespace = " http://tempuri.org/ ")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class Fileupload : System.Web.Services.WebService {     public Fileupload()     {     }     [WebMethod]     public string UploadFile(byte[] fs, string fileName)     {         try      ...

[轉貼] Server 端Post資料到 .ashx

圖片
  出處: http://www.dotblogs.com.tw/hatelove/archive/2011/12/02/asp.net-server-post-data-to-ashx-with-webrequest.aspx 前言 前陣子同事問我一個問題,要怎麼在server端post資料給遠端的.ashx。突然間我還真不知道怎麼做,因為通常都是在client端用ajax呼叫.ashx,如果是網站外的服務,通常都是Web service或WCF,.ashx還真沒碰到過。 所以survey了一下,寫了個小小Sample Code,當個memo。 需求 在server端post資料到.ashx,.ashx處理完後,接收.ashx的response。 範例 .aspx.cs view source print ? 01 protected   void   Button1_Click( object   sender, EventArgs e) 02 { 03      var url =  " http://localhost:13488/serverPostAshx/MyHandler.ashx " ; 04      string   uri =  string .Format( "{0}?who={1}" , url,  "joey" ); 05      WebRequest request = WebRequest.Create(uri); 06      request.Method =  "POST" ; 07      //加上"data=",讓server端可以透過Request.Form["data"]讀取 08      string   postData =  "data={a:1, b:2, c:[3,4]}" ; 09      byte [] byteAr...