Today one of my colleague comes with a problem; he want to display a Powerpoint presentation in his Sharepoint site. But we didn’t got any direct way to display it. They we tweaked the code, to export the Slides to images and display it using the a custom slideshow web part, like the AjaxToolkit slideshow control.
I am attaching the code to export all the slides from a Power Point to Images
string ExportLocation = "C:\\Sample";
Microsoft.Office.Interop.PowerPoint.Application ppApp = new Microsoft.Office.Interop.PowerPoint.Application();
ppApp.Visible = MsoTriState.msoTrue;
ppApp.WindowState = PpWindowState.ppWindowMinimized;
Microsoft.Office.Interop.PowerPoint.Presentations oPresSet = ppApp.Presentations;
Microsoft.Office.Interop.PowerPoint._Presentation oPres = oPresSet.Open("C:\\ScreenShots.ppt",
MsoTriState.msoFalse, MsoTriState.msoFalse,
MsoTriState.msoFalse);
ppApp.ShowWindowsInTaskbar = MsoTriState.msoFalse; //Hiding the application; But it will be displayed always
try
{
Slides objSlides = oPres.Slides; //Getting all the slides
for (int i = 1; i < objSlides.Count - 1; i++)
{
string file = Path.Combine(ExportLocation, string.Format("{0}.{1}", objSlides[i].Name, "jpg"));
oPres.Slides[i].Export(file, "jpg", 800, 600);
}
}
finally
{
ppApp.Quit(); //Closing the Powerpoint application. Sometimes it won't work too.
}
Thanks to ArunKumar, for providing the code snippet.
If you are working with Sharepoint or Infopath sometime you need to use makecab.exe, it is a command line utility to create cab files from Microsoft. You can use makecab utility from command prompt.
Command line output from MakeCab/?
MAKECAB [/V[n]] [/D var=value ...] [/L dir] source [destination]
MAKECAB [/V[n]] [/D var=value ...] /F directive_file [...]
source - File to compress.
destination - File name to give compressed file. If omitted, the
last character of the source file name is replaced
with an underscore (_) and used as the destination.
/F directives - A file with MakeCAB directives (may be repeated).
/D var=value - Defines variable with specified value.
/L dir - Location to place destination (default is current directory).
/V[n] - Verbosity level (1..3)
But I was unable to create the cab file with multiple files using this. After a long search I found one solution from MSDN – Using MakeCab.exe. Then I have created one .ddf file and using the command
makecab.exe /f Sample.ddf
And in the sample.ddf you can specify the file names.
;*** Sample Source Code MakeCAB Directive file example
;
.OPTION EXPLICIT ; Generate errors
.Set CabinetNameTemplate="Sample.cab"
.set DiskDirectoryTemplate=CDROM ; All cabinets go in a single directory
.Set CompressionType=MSZIP;** All files are compressed in cabinet files
.Set UniqueFiles="OFF"
.Set Cabinet=on
.Set DiskDirectory1="Cabs"
image1.gif
image2.gif
mystyle.xsl
manifest.xsf
myschema.xsd
script.vbs
template.xml
upgrade.xsl
;*** <the end>
I think the code is self explanatory.
While working in Infopath forms, there may some situations where you may need to Print the InfoPath form. But the problem of Infopath API is that we can’t specify the printer name for printing. Like this one
InfoApp.XDocuments(0).PrintOut()
The printout method doesn’t have any parameters like Printer name or port etc. As a workaround you can export the Infopath document as Word, and print the document using Word API, where you can specify the printer name. To export the Infopath as Word there is no direct method, but you can do export to “MHT”(MHTML Document), and change the extention to “.doc” and using Word.Application you can open it and Print.
'Creating the Infopath application
Dim InfoApp As New InfoPath.Application()
'Opening the Infopath document.
InfoApp.XDocuments.Open("C:\Sample\template.xml")
'Exporting the document as Word(MHT)
InfoApp.XDocuments(0).View.Export("C:\Sample\Samplex.doc", "MHT")
Let me know if you find any other solutions
While using Word automation with .Net sometimes it is required ti call, word macro’s from C# or VB.Net.
Here is the code to call word macros from VB.Net.
Dim WordApp As New Microsoft.Office.Interop.Word.Application
CType(WordApp, Object).GetType().InvokeMember("Run", Reflection.BindingFlags.Default Or Reflection.BindingFlags.InvokeMethod, Nothing, CType(WordApp, Object), New Object() {"helloworld"})
In the code, helloworld is the macro name.Or you can simply call WordApp.Run("helloworld") will also works fine.
You can also refer link from Microsoft
http://support.microsoft.com/kb/306683