|
Are you saying you want to get the open document itself, or just the path? Keep in mind that Word can have many documents open. You need to get the Word.Application instance from the Running Object Table (ROT). To do that you pass "Word.Application" to System.Runtime.InteropServices.Marshal.GetActiveObject and cast to the ApplicationClass in the Word PIA (Primary Interop Assemblies; these are installed with a development feature of Office 2003 Professional and downloadable for Office XP from http://msdn.microsoft.com[^]. They can also be generated automatically.). Once you've done that you can easily get the active document:
using System;
using System.Runtime.InteropServices;
using Microsoft.Office.Interop.Word;
class ActiveDoc
{
const string WordProgId = "Word.Application";
static void Main()
{
ApplicationClass app = Marshal.GetActiveObject(WordProgId)
as ApplicationClass;
if (app != null)
{
try
{
DocumentClass doc = (DocumentClass)app.ActiveDocument;
if (doc != null)
Console.WriteLine(doc.Path);
}
catch (COMException)
{
Console.Error.WriteLine("No document is open.");
}
}
else
Console.Error.WriteLine("Word is not running.");
}
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
[WebMethod]
public ClassBase DoSomething(ClassBase classbase)
{
...
}
[Serializable]
public abstract class ClassBase
{
...
}
[Serializable]
public class PriorClass:ClassBase
{
...
}
[Serializable]
public class NewClass:ClassBase
{
...
}
PriorClass pc = ServiceRef.DoSomething(priorClass) as PriorClass;//works well
NewClass nc = ServiceRef.DoSomething(priorClass) as NewClass;//exception issue
|
|
|
|
|
You cant cross-cast from an instance of PriorClass to NewClass as they are siblings in your inheritance tree.
|
|
|
|
|
sorry, the correct should be:
PriorClass pc = ServiceRef.DoSomething(priorClass) as PriorClass;//works well
NewClass nc = ServiceRef.DoSomething(newClass) as NewClass;//exception issue
|
|
|
|
|
Ok now that looks better... but without knowing what DoSomething does with the argument passed in its hard to advise as to the problem.
A tip for you though.. on the left hand side of that assignment you should be dealing with your base class - all functionality should be abstract within it. In other words your code should look along these lines
BaseClass pc = ServiceRef.DoSomething(priorClass);
BaseClass nc = ServiceRef.DoSomething(newClass);
pc.SomeCall();
nc.SomeCall();
with SomeCall being abstract/virtual in BaseClass, and implemented in the Concrete PriorClass and NewClass.
|
|
|
|
|
Hi everyone,
I'm having a strange problem with unicode encoding in C# / Macromedia Flash, and I think I need a little explanation to make sure I understand WHERE is the problem.
So, in C#, we have Encoding.UTF8 and Encoding.Unicode . Encoding.UTF8 will encode ASCII characters into 8 bits, and all other characters as 16 bits (accented characters, etc). On the other hand, Encoding.Unicode is actually UTF16 and will encode all characters into 16 bits.
The problem: latin small letter s with caron - š - with character code 0x0161. This letter is encoded into 0x6101 when using Encoding.Unicode or 0x0161 when using Encoding.BigEndianUnicode . However, when using Encoding.UTF8 , this letter is encoded into 0xC5A1.
In Macromedia Flash, strings are apparently encoded using UTF8, as the base ASCII characters are encoded into 8 bits, but the small letter s with caron - š - is encoded into 0x0161.
So now I don't know why is it different in UTF8 in C#?
Any clues will be highly appreciated...
Rado
Radoslav Bielik
http://www.neomyz.com/poll [^] - Get your own web poll
|
|
|
|
|
|
Thanks Mike, this makes sense! Now it seems that the Flash is actually using UTF-16 internally, not UTF-8. I will forward this to our Flash guy.
One more question - is there any easy and straightforward way to convert UTF-16 representation to UTF-8 representation of a letter?
[EDIT]I was thinking about an algorithm, or a simple script, not about the C# Encoding.Convert [/EDIT]
Thanks again!
Rado
Radoslav Bielik
http://www.neomyz.com/poll [^] - Get your own web poll
|
|
|
|
|
Al of you people wil know how to get the position of the mouse pointer in a textBox. But mij problem is i need to get my mouse pointer to a position given in 2 textboxes. Can anyone tell me how to do this because i don't have a clue
The underdog
|
|
|
|
|
Hopefully I got it right that you want to move the mouse cursor to a position, whose coordinates are given in two textboxes.
The following code snippet assumes that only numbers can be entered into both textboxes, cause otherwise the Parse methods might throw an exception.
int x = int.Parse(textBoxX.Text);
int y = int.Parse(textBoxY.Text);
System.Windows.Forms.Cursor.Position = new Point(x, y);
www.troschuetz.de
|
|
|
|
|
Hello C# developers,
I would like to send SMS via my c# code.I am planning to send SMS by using a web site.But how can I provide user name and password for this web site? do you have any sample code for this?
I have made some researches on MSDN web site and all the code samples were about Pocket PC programming.
Can anyone help? How can I do this?
Regards
|
|
|
|
|
I was thinking of creating a simple, specialised task manager. It seems quite easy to use the Diagnostics.Process class to get processes memory and CPU usage.
But I also need to get GDI and USER objects per process. Is there any similar class for that or is it performance counters or WMI I need to look into?
|
|
|
|
|
clatten wrote:
Is there any similar class for that or is it performance counters or WMI I need to look into?
Yes, you do need to use performance counters for this.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi Heath,
thanks for your answer. I did look into the performance objects in PerfMon (I have a XP Home WS at home and a Win2K WS at work) and could not find any counters for the process object. Actually I could not find any counter for this. I have looked with exctrlst.exe and could not find any disabled counters.
So I have to ask if you can point me in the right direction on how to proceed:
1. Do I have to do something to add more counters to the process object (or they might just not are available in WS PerfMon).
2. Is there any other performance object I should look into (but I still want the count per process as in the Task manager).
|
|
|
|
|
If you can't find performance counters that suit your needs, you'll need to P/Invoke native APIs when appropriate, like GetPerformanceInfo or GetProcessMemoryInfo , both defined in psapi.dll on XP and newer. I recommend reading the native performance monitoring and Processes sections of the Platform SDK at http://msdn.microsoft.com/library[^]. The .NET BCL by no means provides a full set of diagnostic APIs for issues like this.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Through googling I later found that the easiest way was to use the GetGuiResources method in User32.dll. This provides the GDI and USER objects counters for each process.
|
|
|
|
|
Hello,
Is there anyone can help on how to access the windows (oulook) address book with the standard dialog. I need to get back name, company, phone number and fax number.
Thanks
|
|
|
|
|
|
In fact, the address book dialog I want to display is this used by Outlook when you click on "TO" button when you send an email. With this dialog you have access to your exchange address book and your personal adress book...
|
|
|
|
|
To use user names for my project. i want to get it from microsoft outlook.
please help me
Thanks,
sivaji raju
|
|
|
|
|
|
hi there !
i am doing a chat app with c#. i have used tcpclient and listener classes to send data across. recently i have encrypted
the data iam sending back and forth with rjindael encryption algorithm. when i did this iam losing some characters on the receiving end. it's sort of truncation. on both the server side and client i perform an asynchronous read with a buffersize of 5120. the sendbuffersize and receivebuffersize for the tcpclient are default which is 8192 bytes.
please tell me what is happening here and guide me.
thanks.
|
|
|
|
|
Have you tried calling Flush() on the encryption provider and/or the TcpClient stream after each write?
|
|
|
|
|
Hi reinux !
i am calling flush() after each call to write. thats already in place.
any more possiblities.
thanks.
|
|
|
|
|
Are you using a language with something other than 1 byte characters? You might be counting characters wrong. For example, say you're working with Japanese transmissions (2 bytes per character). Say there are 50 characters -- that's 100 bytes. But if you count characters rather than bytes, and you send only 50 bytes worth, you'll only get the first 25 characters across.
It's a rare mistake in C#, but it can still happen.
Hope this helps.
|
|
|
|