VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Printing Word without Opening Application

by Vipin S (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 10th August 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Printing Word without Opening Application

Rate Printing Word without Opening Application



// Author-->Vipin S
// Parameter--StrFileName(Egs:-C:\\vipin.doc)
using System;
using System.Windows.Forms;
using Microsoft.CSharp;
using System.IO;
using System.Diagnostics;
using System.Collections;
using Word;


namespace Printing
{
/// <summary>
/// Summary description for Printing.
/// </summary>
public class Printing
{
public Printing()
{

}

public bool Bln_PrintAllFiles(string StrFileName)
{
Word.Application ObjWord =new Word.Application(); //Create Word Application
object M=Type.Missing; //M is missing...hi..hi
object V= StrFileName; //Convert to Object..
object I=false; //Convert to Object

try
{
if(StrFileName.EndsWith(".doc"))     //Ends with .doc. itz Word document....
{
ObjWord.Documents.Open(ref V,ref M,ref M,ref M,ref M,ref M,ref M,ref M,ref M,ref M,ref M,ref M);
ObjWord.PrintOut(ref I,ref M,ref M,ref M,ref M,ref M,ref M,ref M,ref M,ref M,ref M,ref M,ref M,ref M,ref M,ref M,ref M,ref M,ref M);
ObjWord.Quit(ref M,ref M,ref M);
return true;

}
else //for all other types..I did check for .txt,.pdf and .Msg
{ System.Diagnostics.Process P=new Process(); //Create a process
P.StartInfo.FileName = StrFileName.ToString(); //convert ....> Readable
P.StartInfo.CreateNoWindow = true; //Perfect...Create No Window
P.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;//WindowStyle---->HIDDEN
P.StartInfo.Verb = "print";
P.Start(); //Start the process
P.Dispose();
return true;
}
}
catch(Exception ee) //Err Handler.....
{
MessageBox.Show(ee.Message);
return false;
}

}
}


}


Download this snippet    Add to My Saved Code

Printing Word without Opening Application Comments

No comments have been posted about Printing Word without Opening Application. Why not be the first to post a comment about Printing Word without Opening Application.

Post your comment

Subject:
Message:
0/1000 characters