C#


careers
April 29, 2010: 10:51 amfeedback: LokkjuC#, Projects

Though there are a lot of articles out there on office automation in dotnet (most of them telling you not to do it), there are very few covering how to get office automation up and running under IIS7 on a 64bit machine – and it is possible.

I needed to do this recently, and found one hint on how to get it working at http://forums.asp.net/t/1328690.aspx . They key is to use Process to launch the application you need, then attach to it.

Sample code in C#:


Microsoft.Office.Interop.Word.Application app = null;
Process proc = null;
Document doc = null;
try
{
ProcessStartInfo procinfo = new ProcessStartInfo(WORD_PATH, "");
procinfo.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;
procinfo.CreateNoWindow = true;
procinfo.WindowStyle = ProcessWindowStyle.Hidden;
proc = Process.Start(procinfo);
proc.WaitForInputIdle();
app = (Microsoft.Office.Interop.Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
if (app == null) { throw new Exception("Word not found"); }
app.Visible = false;
app.DisplayAlerts = WdAlertLevel.wdAlertsNone;
#region Declare Params
object fileName = filename;
object ConfirmConversions = false;
object ReadOnly = true;
object AddToRecentFiles = Type.Missing;
object PasswordDocument = Type.Missing;
object PasswordTemplate = Type.Missing;
object Revert = Type.Missing;
object WritePasswordDocument = Type.Missing;
object WritePasswordTemplate = Type.Missing;
object Format = Type.Missing;
object Encoding = Type.Missing;
object Visible = false;
object OpenAndRepair = Type.Missing;
object DocumentDirection = Type.Missing;
object NoEncodingDialog = Type.Missing;
object XMLTransform = Type.Missing;
#endregion
doc = app.Documents.Open(ref fileName, ref ConfirmConversions, ref ReadOnly, ref AddToRecentFiles, ref PasswordDocument, ref PasswordTemplate, ref Revert, ref WritePasswordDocument, ref WritePasswordTemplate, ref Format, ref Encoding, ref Visible, ref OpenAndRepair, ref DocumentDirection, ref NoEncodingDialog, ref XMLTransform);
// DO WHATEVER YOU NEED TO HERE
}
finally
{
object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
object OriginalFormat = Type.Missing;
object RouteDocument = Type.Missing;
try
{
((_Document)doc).Close(ref saveChanges, ref OriginalFormat, ref RouteDocument);
doc = null;
}
catch { }
try
{
((Microsoft.Office.Interop.Word._Application)app).Quit(ref saveChanges, ref OriginalFormat, ref RouteDocument);
app = null;
}
catch { }
try
{
proc.Kill();
}
catch { }
}

api
August 26, 2007: 6:16 am: LokkjuC#, Projects

UPDATE:
new google code project page at http://code.google.com/p/iphonefs/

Ok, just got done with getting this to the point it mostly works.
Files are at http://projects.lokkju.com/iPhoneDrive.1.0.2794.12283.zip

Simple instructions:
unzip, run iPhoneDriveControl.exe.
A messagebox will pop up, asking for the location of iTunesMobileDevice.
Select the file, hit ok.
The program will start.
Ignore all the german scrolling in the trace window – the is alpha goddammit.
When it runs, it will find the next available drive letter.
The drive letter will be printed to the Trace window.
The drive letter will be mapped to the phone’s filesystem.
Now you can use Windows Explorer or the command line, makes no diff.

Feel free to submit bugs, but I know there are lots, it is an alpha.

Also, this works just fine on unhacked phones, it will just show your jail root.

For windows obviously, though it might be ported to linux under mono.

If anyone wants to work on the source with me, and knows C#, let me know through comments or email.
I have a svn repo, and you can submit patches or I can give access.

Right now this is semi closed source, but should eventually be released under the GPLv3.
Specifically the CIFS server implementation is not open source yet, and isn’t mine, though the auther keeps saying he might make open source soon.

Once I get the bugs worked out, it will run as a windows service, so you have the drive whenever you plug in your iPhone.

help
May 16, 2007: 7:24 amhome: LokkjuC#, Projects

Something you see all the time in Javascript is using the flash and fade of the background color of an object to indicate some form of activity – success, error, etc. There is nothing that makes this easy in C#, but I managed to do it using some hacky Invoke calls.
Code is after the break, but you can download the entire test project: ColorAnim Test Project (VS2005)

(more…)

Make payments with PayPal - it's fast, free and secure!
faq

careers