0

I can't even get off the ground.I DO KNOW HOW TO ADD REFERENCES, (this."""mshtml""" NOT[working])

using System;
using system.text;
using mshtml; // i cant seem to access this

I'm confused on why when I type mshtml it's in capitals, MSHTML. The problem I'm having is I'm just using a variety of tutorials but can't seem to even start them as this is my first problem.

I have manually browsed when adding references to my application but it doesn't seem to work. I keep getting the capital letter version, except there is no capital letter version of MSHTML.dll in my directories on my PC. If for some reason I don't have this file can it been downloaded for free safely or are my tutorials just too old?

Also just to let you know I understand where these files are meant be, in regards to folders locations ect. I thought if I just add the reference in to my project it should just be there.

joshua
  • 676
  • 1
  • 5
  • 19
  • First things first. C# is case sensitive, so specify exactly the namespace as using System.Text; otherwise you can't get what you want – Steve Mar 27 '12 at 15:31
  • why do people add coments to the sample data , your comment solved everything lol thanks... – joshua Mar 27 '12 at 15:42

4 Answers4

2

I think you have a misunderstanding by your terms 'capital letter version'.

The name of a dynamic link library, although usually indicative of its purpose and aptly named, isn't strictly tied to the contents of the assembly. You can call it what you want (within reason and limits of the system) and the code inside remains the same.

If you've added a reference to a 'MSHTML.dll' file, then it is very probable that a namespace of 'mshtml' is defined - I didn't say ideal, but probable. Casing within the code does matter though - so if, for instance, Intellisense is showing you a case-variant version of what you're typing then it's probably that. Either way, it won't be what you've been typing if you ignore it.

If you could reference the tutorials you were following then it would likely be easier to see what the actual problem was. Other than that, go ahead with the code that it provides.

As an aside, I'd recommend some reading up on Assemblies in .NET.

Grant Thomas
  • 44,454
  • 10
  • 85
  • 129
2

Thank you for pointing out that this is your first C# program. It helps us understand the level at which to try to answer.

First, I'd like to address a statement you made:

there is no Capital letter version of MSHTML.dll in my directories

It seems that you're confusing Namespaces with .dll names, which is something I struggled with myself at first. There's a full explanation here, but it may be too technical for beginner level developers.

In a nutshell, at the top of the file where your "using" statements are, you're telling the compiler where to look for certain classes and code by Namespace.

A Namespace is a logical grouping of code. For convenience and clarity, developers group similarly functioning code into Namespaces. For example, Data Access code is in the System.Data Namespace.

When adding a .dll you're adding an actual file reference. In a less-confusing world, .dlls would be named to reflect the Namespaces contained within them. However, it's not always that simple. It' is perfectly possible for me to create a dll named "DaveStratton.dll" that contains Booyah.Encryption, Simple.Functions or any other Namespace I want. There really is no correlation except by convention, and it's not enforced."

For example, if you look in the MSDN Library at the System.Data.SqlConnection class.
The Class name is actually SqlConnection, and it lives in the System.Data Namespace. The System.Data Namespace is contained in the System.Data.dll. (because the developers were following convention and did it this way for clarity.) Screenshot below:

enter image description here

If you look at other classes, you may find discrepancies.

For example, the System.Configuration.SettingsBase class: The SettingsBase class in in the System.Configuration namespace, but if you look at the assembly information, you'll see that it's in System.dll. And the System.Configuration.ConfigurationManager is in the System.Configuration.dll.


So, long story short, you need to know the Assembly (.dll) name when adding a reference in Visual Studio, but you need the class/assembly name when writing your code. In your using statement, you need capital letters because the Namespace is capitalized, ewven if the .dll isn't.

David
  • 72,686
  • 18
  • 132
  • 173
  • I understand the concepts and the idea you could say i gennerally just played with other languages. I understand what your getting at im crap... these references im trying to access doent seem to bond to the project for instance"using mshtml" throws errors, but using MSHTML doesnt.im not sure if these are the same or yeah i got no Idea – joshua Mar 27 '12 at 15:48
  • I'm absolutely not saying you're crap... I'm saying I struggled with it myself, so I know where you're coming from. Sorry if I offended you, my intent was 100% the OPPOSITE of meaning to insult you. – David Mar 27 '12 at 15:52
  • i was joking, iv been playing with other languages, they dont seem to add references i generally import them with codes, class files what not.i might sleep on it 3 am anyways first attempted try tomorrow if not move to c++ – joshua Mar 27 '12 at 15:55
  • I will accept your answer, im just assuming most people havent ran into this problem so i may isolated until i read more of the docs on the fundementals of c#, lol – joshua Mar 27 '12 at 16:01
1

it sounds like you need to add a reference to your project first. Open up your solution, in the right project explorer, expand references, right click references to add a reference. Now find the Microsoft.mshtml and add that as a reference.

Ricky
  • 840
  • 1
  • 8
  • 11
  • Also, you aren't looking to find a DLL, just find it in the .NET tab. Unless you are using the AxWebBrowser and not the .NET managed web browser in the tutorials. If so, let me know and I'll tell you how to add the reference to that. – Ricky Mar 27 '12 at 15:33
  • Now find the Microsoft.mshtml and add that as a reference. this is not there, also its not available under the net tab either – joshua Mar 27 '12 at 15:43
1

See here for your using problem, you need to add a reference (right click project, add reference) to this particular COM lib 1: How do I use MSHTML in VB.NET?

Community
  • 1
  • 1
ldgorman
  • 1,553
  • 1
  • 14
  • 39