|
I would recommend that you pay too much attention to samples. Study the documentation and if you really want to be elite use ildasm.exe (or .NET Reflector, but then you use geek points if you don't use the IL view ) to view the implementation. If you're having problems understanding the documentation (hey...it happens!) the samples can sometimes help.
I actually have been reporting several problems in samples (like GetProcAddress(TEXT("SomeFunction")); , since GetProcAddress only accepts LPCSTR , which is ANSI and the TEXT macro causes strings to be treated as Unicode when _UNICODE is defined) and I recommend you do the same. Most topics have a link at the bottom to send feedback. All of the .NET Framework SDK topics should.
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]
|
|
|
|
|
I can't say why their examples use Type.GetType but I could have guessed that typeof is simply faster than Type.GetType .
Check this out...
System.Type t = typeof(System.String);
Seems to generate this il:
<br />
ldtoken [mscorlib]System.String<br />
call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle)<br />
While...
<br />
System.Type t = System.Type.GetType("System.String");<br />
Seems to generate this il:
<br />
ldstr "System.String"<br />
call class [mscorlib]System.Type [mscorlib]System.Type::GetType(string)<br />
Without going farther, I suspect that GetTypeFromHandle is way more speedy than the generic GetType . One has the handle reference readily available for inspection while the other has to go looking for it.
|
|
|
|
|
The latter also has a change of breaking at runtime if the Type is not defined in the current assembly. The former (typeof ) is checked at compile time and you can be sure that the type will be found (so long as the entire assembly isn't missing or the version redirected to where the Type isn't defined) at run-time.
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]
|
|
|
|
|
Heath Stewart wrote:
latter also has a change of breaking at runtime if the Type is not defined in the current assembly.
Good point! Even more reason to use typeof. It would be pretty easy to mistype the class name with Type.GetType() and not catch it.
|
|
|
|
|
Thats about right .... with type of the type is kindda known .. .where as in the other one it is looked up from a string literal .....
- The Outlander -
|
|
|
|
|
Hi ~
I am generateing a Word Document in C# and need to put page numbers and information in the footer.
However, when I add information to the Range.Text the page numbers do not display correctly.
This is what I get -
Page 1 of 1 ( Same on all the pages )
*******************
* Somthing here *
*******************
This is what I need -
Page 1 of 47
*******************
* Something Here *
*******************
This is the code I have -
_WordDoc.Sections.First.Footer.Item(Word.WdHenderFooterIndex.wdHeaderFooterPrimary).Range.Text = "Page X of Y";
_WordDoc.Sections.First.Footer.Item(Word.WdHenderFooterIndex.wdHeaderFooterPrimary).Range.InsertAutoText();
_WordDoc.Sections.First.Footer.Item(Word.WdHenderFooterIndex.wdHeaderFooterPrimary).Range.Text += "\n" + String1 + String2 + String3;
Michele
Mercer Engineering Research Center
mstusak@merc.mercer.edu
|
|
|
|
|
When doesn't it display correctly? When you open the document in Word or when you print it? In the latter case, make sure to set Options.UpdateFieldsAtPrint to true .
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]
|
|
|
|
|
Thank you for your help - it does not display correctly when I open the document in Word.
- Michele -
Michele
Mercer Engineering Research Center
mstusak@merc.mercer.edu
|
|
|
|
|
Just to make sure that the auto-text conversion / recognition is working correctly, when you open it in word find that portion of the document footoer and select either the "X" or "Y" (what they originally were). These should appear as gray blocks that are fields. Make sure that they are fields. If not, you'll have to actually insert the auto-text entries rather than getting Word to recognize that they are. Let me know if they are fields and I can post some example code if not.
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]
|
|
|
|
|
No the auto-text conversion/recognition does not see the "X" or "Y" as fields if I place any other text in the footer. However, if I do not place any text and only use the auto text the conversion/recognition does place fields in the footer.
Michele
Mercer Engineering Research Center
mstusak@merc.mercer.edu
|
|
|
|
|
Then you'll have to add it as an AutoText entry itself. Please note this is sample code and is not checked, but should give you the right idea.
_WordDoc.AttachedTemplate.AutoTextEntries("Page X of Y").Insert(
_WordDoc.Sections.First.Footer.Item(WdHeaderFooterIndex.wdHeaderFooterPrimary).Range,
true);
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]
|
|
|
|
|
I understand what you are saying, however I can not access the Templates. AttachedTemplate is not supported in C#. The closest I have come is -
_WordDoc.Application.Templates.Item(ref Index).AutoTextEntries.Add("Page X of Y", _WordDoc.Sections.First.Footer.Item(WdHeaderFooterIndex.wdHeaderFooterPrimary).Range)
- but this is not working. Do you know of any other way to access the templates in C#.
Michele
Mercer Engineering Research Center
mstusak@merc.mercer.edu
|
|
|
|
|
The Document class does define the AttachedTemplate property but you must cast it to the proper type, which is the Template class. Since this is an interop assembly, members are not always strongly typed as they are in .NET because some times objects simply return IDispatch in a retval parameter. As I mentioned in my previous post, the code wasn't verified but it is close:
Template tmpl = _WordDoc.ActiveDocument.AttachedTemplate as Template;
if (tmpl != null)
{
} Looking through the assembly - which you can do using ildasm.exe that ships with the .NET Framework SDK, or .NET Reflector[^], you can often see what must be done using COM interop assemblies. For documentation, use the automation or object model documentation for a product since an interop assembly marshals calls to the COM server (the automation object) using the same type definitions from a typelib as, say, VB6 would do.
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 folks
i want to print my statistical results directly from the printer without saving in the file or so
how can i do that
thaxs
|
|
|
|
|
Read the documentation[^] for the PrintDocument class in the .NET Framework. Like drawing on a control (overriding OnPaint or handling the Paint event), you draw into the document using a Graphics object passed to you. The difference here is that you have to be mindful of the print margins and whether or not you require more pages.
Click "Search comments" above and search for "PrintDocument" to find a few examples. You might also use the site search (the text box below the logo on every page) for "PrintDocument" as well to see how to print in .NET.
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 folks!
how to run an AVI clip in a window application form
if some can guide me
thxs
|
|
|
|
|
Add a reference to the Windows Media Player, add it to the ToolBox, then drop it on your form. I think you can figure it out from there.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hello All,
I get an error when i use single quotes in the data inserted with sql statment.and i am already finished the programes i can'nt change it to pramertized quiers.
for example:
insert into test (name,age) Values('jon'thes','30')
please help with any way...
regards,
Hay
|
|
|
|
|
|
Thanks for your reply...
I can'nt change the programe because i am already finished it and it will take a long time to change all the programes.
Regards,
Hay
|
|
|
|
|
webhay wrote:
I can'nt change the programe because i am already finished it
Looks to me as if you are not finished it because it has a pretty major flaw. Not only do you have the problem of being able to insert data with apostrophes in it, but your current code leaves your program (and database) wide open to a SQL Injection Attack. See: http://www.codeproject.com/cs/database/SqlInjectionAttacks.asp[^]
webhay wrote:
it will take a long time to change all the programes
It shouldn't take so long to make a change like this because all the changes should really be concentrated in to small areas of the application. You might like to read up on Design Patterns and specifically about creating a Data Abstraction Layer (DAL).
My: Blog | Photos | Next SQL Presentation
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More
|
|
|
|
|
In addition to what Colin is saying, if you would have done it correctly in the first place (using parameterized queries), this would never have been a problem. The SQLParameter objects automatically inspect your parameters for characters that need escaping, such as the quotes, and make corrections as needed. They even scan that params for certain types of attacks.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
if u want sql ignore the single quotes write 2 single quotes :
Values('jon''thes','30')
Values('jon
'' thes','30')
Values('jon
'' thes','30')
To study, study and only to study
|
|
|
|
|
|
SqlCommand command = new SqlCommand("INSERT INTO test (name, age) Values(@Name, @Age);
command.Parameters.Add("@Name", "jon'thes");
command.Parameters.Add("@Age", "30");
Like Colin said, the change isn't reallly that difficult and it's one that needs to be made for security's sake.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: He has a funny face. And he's my son.
Judah Himango
|
|
|
|