TITLE-TEXT

SHORT DESCRIPTION HERE , ...
title

TITLE-TEXT

SHORT DESCRIPTION HERE , ...
title
ewefr

CSharp語法 下載Word 合併Word Word轉Pdf

張貼者: Tony

using Word = Microsoft.Office.Interop.Word;//這個要先加入Microsoft.Office.Interop.Word參考 
using System.Reflection;//這個記得參考 

下載Word
/// <summary>
        /// 下載Word
        /// </summary>
        /// <param name="FilePath"></param>
        /// <param name="FileName"></param>
        /// <param name="response"></param>
        /// <returns></returns>
        public static bool DownloadWord(string FilePath, string FileName, HttpResponse response)
        {
            try
            {
                FileInfo DownloadFile = new FileInfo(FilePath + FileName);
                response.Clear();
                response.ClearHeaders();
                response.Buffer = false; 
                 //Response.ContentType指定檔案類型  
                 //可以為application/ms-excel || application/ms-word || application/ms-txt  
                 //application/ms-html || 或其他瀏覽器可以支援的文件 
                response.ContentType = "application/octet-stream";//所有類型 
                 //下面這行很重要, attachment 参数表示作為附件下載,可以改成 online線上開啟 
                 //filename=FileFlow.xls 指定输出檔案名稱,注意其附檔名和指定檔案類型相符, 
                 //可以為:.doc || .xls || .txt ||.htm 
                response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8));
                response.AppendHeader("Content-Length", DownloadFile.Length.ToString());//取得檔案大小 

                response.WriteFile(DownloadFile.FullName);
                response.Flush();
                //response.End();


                return true;
            }
            catch
            {
                return false;
            }

        }


合併多個Wold
/// <summary>
        /// 合併多個Wold
        /// </summary>
        /// <param name="InFilePath"></param>
        /// <param name="OutFilePath"></param>
        /// <returns></returns>
        public static bool MergeWord(string[] InFilePath,string OutFilePath)
        {
            try
            {
                object missing = Missing.Value; 
                object iLastWord = InFilePath.Last();//最後合併的word
                object oOutputDoc = OutFilePath;//合併檔 
                object oPageBreak = Word.WdBreakType.wdSectionBreakContinuous;
                //object oPageBreak = Word.WdBreakType.wdLineBreak;//接下行合併(LineBreak) 
                //object oPageBreak = Word.WdBreakType.wdPageBreak;//接下頁合併(PageBreak) 

                Word.Application wordApp = new Word.Application();

                Word.Document origDoc = wordApp.Documents.Open(ref iLastWord, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
                origDoc.Activate();
              
                for (int i = 0; i < InFilePath.Count();i++)
                {
                    if (i == (InFilePath.Count() - 1) || InFilePath.Count() == 0)
                        break;
                    wordApp.Selection.InsertFile(InFilePath[i], ref missing, ref missing, ref missing, ref missing);
                    wordApp.Selection.InsertBreak(ref oPageBreak);
                }

                wordApp.ActiveDocument.SaveAs(ref oOutputDoc, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); 
                wordApp.ActiveDocument.Close(ref missing, ref missing, ref missing); 
                wordApp.Quit(ref missing, ref missing, ref missing);    //加這行可以 Kill WINWORD.EXE process 

                return true;
            }
            catch
            {
                return false;
            }
        }


Word轉Pdf
/// <summary>
        /// Word轉Pdf
        /// </summary>
        /// <param name="WoldFilePath">Wold路徑</param>
        /// <param name="PdfFilePath">Pdf路徑</param>
        public static bool ConvertWordtoPdf(object WoldFilePath, object PdfFilePath)
        {

            // 在此处放置用户代码以初始化页面
            object Missing = Type.Missing;

            Word.Application WordApp = new Microsoft.Office.Interop.Word.Application();

            //必须设置为不可见
            WordApp.Visible = false;

            try
            {

                //创建以strTemp为模板的文档
                //object oTemplate = Server.MapPath(strTemp);
                Word.Document WordDoc = WordApp.Documents.Add(ref WoldFilePath, ref Missing, ref Missing, ref Missing);
                WordDoc.Activate();


                //对标签"Title"进行填充
                //string strBM = "Title";
                //object objBM = strBM;

                //if (WordApp.ActiveDocument.Bookmarks.Exists(strBM) == true)
                //{
                //    WordApp.ActiveDocument.Bookmarks.get_Item(ref objBM).Select();
                //    WordApp.Selection.TypeText("公文標題");
                //}

                object FileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;

                //保存为新文件
                //object oNewFileName = Server.MapPath(newFileName);
                WordDoc.SaveAs(ref PdfFilePath, FileFormat, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing,
                ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing, ref Missing);
                WordDoc.Close(ref Missing, ref Missing, ref Missing);
                WordApp.Quit(ref Missing, ref Missing, ref Missing);

                return true;
            }
            catch
            {
                return false;
            }

        }
        #endregion

    }

ASP.NET 前端寫C#

張貼者: Tony

<dx:ASPxImage ID="ASPxImage1"
     ImageUrl='<%#Convert.ToInt32(Eval("ORDER_NM")) == 2 ?  "~/Manager/images/b1.gif" : "" %>'
     Visible='<%#Convert.ToInt32(Eval("ORDER_NM")) == 2 ?  true : false %>'
     runat="server">
</dx:ASPxImage>

在Windows 7「命令提示字元」使用「telnet」指令

張貼者: Tony

在預設的情況下,使用Windows 7 「命令提示字元」是不能無法下「telnet」指令的。
因此要先對Windows 7 做開啟「telnet」指令的動作,如下:
(1) 開啟「控制台」
(2) 在「程式集」項目下,點選「解除安裝程式」
(3) 點選左側「開啟或關閉Windows功能」
(4) 對「Telnet 用戶端」打勾

使用Gmail當作寄信主機

張貼者: Tony

using System.Net;

c#
---------------------------------------------------------------------------------------
string fromEmail = "service@gmail.com";
string fromName = "Manager";
MailAddress from = new MailAddress(fromEmail, fromName, Encoding.UTF8);
string toEmail = "tony1017888@gmail.com";
MailMessage mail = new MailMessage(from, new MailAddress(toEmail));
 string subject = "Test Subject";
 mail.Subject = subject;
 mail.SubjectEncoding = Encoding.UTF8;
 string body = "Test Body";
 mail.Body = body;
 mail.BodyEncoding = Encoding.UTF8;
 mail.IsBodyHtml = false;
 mail.Priority = MailPriority.High;
  // SMTP Setting
  SmtpClient client = new SmtpClient();
  client.Host = "smtp.gmail.com";
  client.Port = 587;
  client.Credentials = new NetworkCredential("username@gmail.com", "password");
  client.EnableSsl = true;
  // Send Mail
  client.Send(mail);
  // Sent Compeleted Eevet
   //client.SendCompleted += new SendCompletedEventHandler(client_SendCompleted);

The Will Will Web

技術分享
MVP版主

重灌狂人

資訊分享

wowboxBlog

提供網頁設計相關資訊

KingKong Bruce記事

技術分享

C# Examples

csharp相關技術與範例

黑暗執行緒

技術分享
MVP版主

杨延成

技術分享
作者文章對於EF有詳細介紹

月光下的嘆息

工具分享
介紹許多好用的工具程式

Dot blogs

DotNet

格子樑/艾倫郭

技術分享
MVP版主