|
How do I take an arbitrary string and UTF8 encode it using System.Text.Encoding.UTF8? I found out how to write strings and how to convert byte data, but not how to convert strings. You'd think this would be easier; maybe I'm missing something.
(I'm using C# by the way).
|
|
|
|
|
Use Encoding class in System.Text namespace.
Basically to convert, you first set up encoding. Let's say you have a simple string that you named simpleS. Here is the code that would convert:
Encoding ascii = Encoding.ASCII;
Encoding utf8 = Encoding.UTF8;
byte[] simpleBytes = ascii.GetBytes(simpleS);
byte[] newbytes = Encoding.Encode(ascii, utf8, simpleBytes);
that's it. Key here is static Encode method provided by Encoding class. Once you have the new byte array, you can convert it to char array of utf8 encoded chars.
I hope this is of some help. MSDN documentation also has a very similar example and more stuff on this encoding. I know I used it for the project I worked some time ago.
|
|
|
|
|
the method of msdn can only used in the case that you exactly know which
version of framework installed in client machine.
But generally we are in this case that we build a application under
framework1.1 and we don't know the version of framework on client machine.So
it seems the only way that we can do is bet the version of client.My god!!!
I mean we can not let the same copy of 1.1 application run either on framework1.1 or on framework1.0.
Is that true??
lost my way
|
|
|
|
|
why don't you just install the 1.1 framework? The two frameworks will run side by side - the only issues I have come across is that 1.0 ASP.NET apps will have to cope wioth the new 1.1 security feature of not allowing tags (and other things) to be placed in element data. i.e "<a" typed="" in="" an="" edit="" box="" will="" throw="" error="" 1.1="" and="" 1.0="" if="" not="" handled="" or="" prepared="" for="" when="" is="" installed.=""
<p="" align="right">Technically speaking the dictionary would define Visual Basic users as programmers. But here again, a very generalized, liberal definition is being employed and it's wrong - just plain wrong - Tom Archer 5/12/02
|
|
|
|
|
I am sure a lot of you have come across .NET based portals such as IBuySpy and DotNetNuke.
Has anyone else come across other portals based on the .NET framework?
The only other one I have come across is PassagePortal (www.cubiccompass.com).
Any suggestions? And any suggestions to other portal frameworks written in say perl/php/asp/jsp etc
(I am sure there must be a few I have missed in my google searching)
Technically speaking the dictionary would define Visual Basic users as programmers. But here again, a very generalized, liberal definition is being employed and it's wrong - just plain wrong - Tom Archer 5/12/02
|
|
|
|
|
Problem:
I have a really complex class library project that I am sure has an awful lot of redundant code (properties, methods, etc...) that are not used.
I want to be able to generate a report of which methods, properties etc of my object model's classes are referenced throughout the other dependant projects etc.
Question:
Is there an application, perhaps a VS.Net Add In that does this already? If not does anyone have any implementation suggestions before I spend the rest of today reinventing the wheel?
Ta muchly
JBoy
|
|
|
|
|
Has anyone used the Bitmapeditor/Imageeditor class in .NET? I looked at it this weekend and could not get it to do anything. My best guess is that you must call the "EditValue" method to run the thing, but that apparently requires having an IServiceProvider. How do you get one of those?
|
|
|
|
|
OK, I have basic and probably simple question for you guys...
Here is the situation:
Assuming:
1. I have WinForm Control ("UserControl1") sitting on HTML page, let's assume his name on HTML layout is "ctrl";
2. I have property of that control named "Object" that has set method;
3. My HTML script does the following:
ctrl.Object = ctrl
I'm setting Object property back to the value of "this" on the site of the control.
So, basically, i understand that .NET class through RCW get's converted to IDispatch and then this IDispatch (probably with new CCW) get's passed back to the control.
Now, it's not surprising that after that trip I'm getting
public object Object
{
set
{ m_object = value; <
}
at <> m_object of type "System.__ComObject"....
Now the question: Using what operation could I convert m_object from "System.__ComObject" to my original "UserControl1" type???!!!...
And if you tell me that this is impossible -- your hyped .NET Framework sucks!!!...LOL
Please, don't refference Marshal::CreateWrapperOfType -- cause id doesn't work...
Also, maybe you can give me an example on how I could enumerate WinForm controls on HTML page, from inside one of them and get native .NET classes for each of them -- maybe there is some method -- don't refference "Container" or "Parent" control properties, because they are both nulls (probably because IE is not managed container)...
Anyway, any answer maybe of help...

|
|
|
|
|
lets get this straight are you trying to manipulate a COM object that is hosted in the client browser from the server side code? if so - you can't (not directly but there is nothing stopping you adding javascript to manipulate the object). if not - then you'll have to make your clarify your question.
maybe by source code extracts
Technically speaking the dictionary would define Visual Basic users as programmers. But here again, a very generalized, liberal definition is being employed and it's wrong - just plain wrong - Tom Archer 5/12/02
|
|
|
|
|
Server is not involved at all..
Simple, Container hosts WebBrowser -- now WebBrowser hosts .NET control -- container queries that WebBrowser for HTML content and get's IDispatch of that control from IHtmlElement...
Having that IDispatch now Container without any WebBrowser or HTML involvement can call methods on that .NET object... Right???...
If so, reverse should be true -- meaning that .NET object getting IDispatch of some other components should be capable of recognizing .NET controls having that IDispatch -- Right?... So, that was my original question...
BTW: I know an answer... Instead of using just ctr --> you must just use "ctrl.object"... So, script line will look like this:
ctrl.Object = ctrl.object --- hehehehe... UGLY!!!...
But seriously: All those .NET Gurus, are just GURUs in there own world!!!...
Yesterday I had pretty good dinner and at night when I was in a deep sleep, suddenly I waked up with a terrible pain in my stomach!!!... Did you ever have this???... So, while running to the bathroom and in there I suddenly realized -- I didn't have any "delegate" for that pain -- and I didn't created any "EventHandler" for it -- not to say that I was not planning to call the base class implementation (interesting, what would it be???LOL)... It just happened!!!...
Enough joking!!!...
So, my point is: You have a pointer which was Marshalled and UnMrashalled, and/or Split and Restored, and/or Divided/Multiplied.... Good system should be able to discover and restore it's Native Type... What is interesting --> that Marshalled IDispact supports IManagedObject even after RCW<->CCW... So, somebody was realy LAZY!!!... OK???!!!...
Regards to ALL MSFT GURUS!!!...
|
|
|
|
|
ah I see what you are trying to do now - does the object host the IDispatch interface? best way would be to see if you can manipulate it via javascript on any exposed methods / properties.
Now this is really a COM question not a .NET one - is it possible to cast the interface you get from the query of IHtmlElement castable (bad english I know) into a .NET object - Sorry but there is no guarantee of that as there is no guaranteee in C that an interface can be cast into the supporting object (proxies, tear off interfaces etc and the like)
Have you come across the samples that shows how to host a .NET control in a webbrowser? see the authpring custom controls at http://samples.gotdotnet.com/quickstart/aspplus/[^]. I can't remember if any of these uses javascript to manipulate the contents
I know this doesn't answer your question but it leads us on a road to find an answer.
Technically speaking the dictionary would define Visual Basic users as programmers. But here again, a very generalized, liberal definition is being employed and it's wrong - just plain wrong - Tom Archer 5/12/02
|
|
|
|
|
"does the object host the IDispatch interface?" Man, you are probably one of those who got into the crowd of MSFT beleivers that CLR has nothing to do with COM!!!... Sure -- each object and type in CLR hosts IDispatch -- it's just hidden by implementation, but could be exposed at anytime...
From what you are writing I understand you are "language" guy -- casting or not casting -- that something what language allows you to do and not really how it's implemented and if implementation allows you to do that, even if language does not -- then there must be some "trick" to be performed...
As to my original question -- forget it -- I have found an aswer...
About sample -- listen: I'm not reading samples -- I'm usually writing them -- just very few I'm showing to the crowd...
My point was:
.NET is great and no question server site programming could be speed up and improved;
as to the client -- I'm not so sure...
Also:
I'm really pissed of by so many young ".NET GURUS" who invented CLR and who are so proud of themselves and etc... They are claiming that this is the best environment and etc, and so on.... While in reality: no questions they performed nice job in Object Data definition and implementation of endless number of namespaces and componentrs, while I would say very poor one and almost nothing in functional logic...
Just few examples:
1. During 11+ years of COM, standard property browser is not part of OS, however only after 2 years of .NET it is ==> confirms that they did a good job on implementation front, but very poor on COM -- Right???;
2. About poor functional logic: my previous message about stomach problem at night was not an accident -- those hyped "Delegates" -- this is just pure wrong -- Client Doesn't have to subscrive for an event at least on Programming level -- Even if he doesn't -- he still should be notified(1) -- and second -- Ideal Event implementation shouldn't require me as a programmer to write even 1 line of extra code, and of course shouldn't require me to "call base class, or things will not work"... As well as I shouldn't check for delegates to be not null -- and etc., etc., etc....
I'm not proposing any implementation here -- I'm just pointing the fact that CLR implementation is not the best...
3. Exposing WinForm Controls as an ActiveX Controls was dropped -- why???... Somebody was just LAZY -- you have reflection, so you can generate TypeLibrary on the fly -- they are saying that Each Event has different interface, therefore one [default, source] can't be generated -- wrong -- this is just implementation detail -- create an extra object that will advice real .NET component on all outgoing interfaces, collect them in one, create collective type library and send it back to subscriber as one source both for events and collected type library -- why this simple thing han't been done???...
Anyway: the real trouble is -- stupid middle and high level managers are planning to move there developments to new CLR platform -- that's fine for companies that are just starting new developments... This is absolutely stupid for owners of currently successfull client site unmanaged systems... Unfortunately only low level programmers understand this... But it's killing very good products...
Still waitingg for MSFT that is giving advices to those "stupid managers" --to see at least one container application like Excel and/or Word and/or IE written completely as managed!!!....
Any scenario is fine with me though... The more mess MSFT creates the more job for me...hehehehe...
Regards ;P;)
|
|
|
|
|
fine so - you found an answer - mind sharing it with us are you one of those take take take and never give back people
|
|
|
|
|
Anonymous, are you able to read????...
I thought I gave an answer:
>> Assuming:
1. I have WinForm Control ("UserControl1") sitting on HTML page, let's assume his name on HTML layout is "ctrl";
2. I have property of that control named "Object" that has set method;
3. My HTML script does the following:
ctrl.Object = ctrl <<<<====!!!!
I'm setting Object property back to the value of "this" on the site of the control......
<<
In my next message I gave an answer:
>>
You should use:
ctrl.Object = ctrl.object <=== Check "ctrl.object" here, instead of just "ctrl"...
Now:
"ctrl" is IHtmlObject wrapper created by IE around real .NET IDispatch, while:
"ctrl.object" is IDispatch of an Object itsel (doesn't have to be .NET BTW)...
As to me never giving back -- maybe... But I never take either... ;);P
|
|
|
|
|
Okay I see where you coming from but...
Originally you seemed to be accessing your code from .NET and now you seem to be to just doing it via javascript. Is this the case are you still trying to turn your IHTMLElement into the original object or are you just sticking with the exposed IDispatch
Technically speaking the dictionary would define Visual Basic users as programmers. But here again, a very generalized, liberal definition is being employed and it's wrong - just plain wrong - Tom Archer 5/12/02
|
|
|
|
|
igor1960 wrote:
The more mess MSFT creates the more job for me...hehehehe...
Ok, you solved your own problem before the gurus. Sounds like you are more interested in showing others how smart you really are. Don't get me wrong, we need more people like you. If you post your code, ideas, observations, and criticism (of microsoft) as articles, it will be more interesting.
|
|
|
|
|
"Don't get me wrong, we need more people like you"...
And who the heck are YOU???!!!
Why do I need to criticise MSFT???!!! It's doing it's best providing me an my family with "bread and butter"!!!...
What I'm criticising -- middle and top level management of other companies, that are very fast in catching next hype in order to preserve there position in hierarchy -- those guys are really "empty" and the only reason for there existance is mess they are creating as well as the only ability to play golf and drink!!!...
As to technical issues -- .NET is great, except because it is so, it's pretty simple to implement simple tasks, while difficult to perform and/or have knowledge on how to implemet difficult/not ordinary ones...
That's it...
|
|
|
|
|
"And who the heck are YOU???!!!"
I am Anonymous101. If you think the name doesn't give enough information, I could change it to something like Anonymous1960.
"Why do I need to criticise MSFT???!!! It's doing it's best providing me an my family with "bread and butter"!!!...
What I'm criticising -- middle and top level management of other companies, that are very fast in catching next hype in order to preserve there position in hierarchy -- those guys are really "empty" and the only reason for there existance is mess they are creating as well as the only ability to play golf and drink!!!..."
Looking at the number of exclamation marks, it seems that you have more anger in your chest than a suicide bomber. Why? Let me guess, you think .NET has made programming too easy and therefore takes some of the privileges away to smart guys like you, right?
Either your confidence or your skill is overrated. 
|
|
|
|
|
|
Hi,
how to enable editing in propertygrid? A normal enum can be edited via Properties (F4). But how to design a enum with FlagsAttribute? Is there a UITypeEditor which provides a checkedlistbox?
.:[Greets from Jerry Maguire]:.
|
|
|
|
|
// Stephen Toub
// stoub@microsoft.com
//
// FlaggedEnumEditor.cs
// UITypeEditor for flag enumerations
//
// July 26th, 2002
// v1.0.0
//
// To Use:
// [Editor(typeof(FlaggedEnumEditor), typeof(UITypeEditor))]
// public SomeFlaggedEnum ExampleProperty { get { return _theEnum; } set { _theEnum = value; } }
using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing.Design;
using System.Windows.Forms.Design;
namespace Toub.Windows.Forms.Design
{
/// <summary>Editor for flag enumerations.</summary>
public class FlaggedEnumEditor : UITypeEditor
{
#region Construction
/// <summary>Initialize the editor.</summary>
public FlaggedEnumEditor() {}
#endregion
#region Editting Values
/// <summary>Edits the specified object's value using the editor style indicated by GetEditStyle.</summary>
/// <param name="context">An ITypeDescriptorContext that can be used to gain additional context information.</param>
/// <param name="provider">An IServiceProvider that this editor can use to obtain services.</param>
/// <param name="value">The object to edit.</param>
/// <returns>The new value of the object.</returns>
public override object EditValue(
ITypeDescriptorContext context, IServiceProvider provider, object value)
{
// Make sure the context and the property are valid.
if (context != null && context.Instance != null &&
context.PropertyDescriptor != null &&
context.PropertyDescriptor.PropertyType.IsEnum &&
provider != null)
{
// Create the listbox for display
CheckedListBox listBox = new CheckedListBox();
listBox.CheckOnClick = true;
// Get the editor used to display the list box
IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
// Get all of the names in the enum and use them to populate the listbox.
Type t = context.PropertyDescriptor.PropertyType;
foreach(string enumName in (string[])Enum.GetNames(t))
{
// We add the enum name, but only if it is selected.
bool isChecked = (((int)value) & (int)Enum.Parse(t, enumName)) != 0;
listBox.Items.Add(enumName, isChecked);
}
// Display the list box
edSvc.DropDownControl(listBox);
// Get all selected values
int enumIntValue = 0;
foreach(string str in listBox.CheckedItems) enumIntValue |= (int)Enum.Parse(t, str);
// Return the new enum
return Enum.ToObject(t, enumIntValue);
}
// Something went wrong; just return the original value
return value;
}
/// <summary>Gets the editor style used by the EditValue method.</summary>
/// <param name="context">An ITypeDescriptorContext that can be used to gain additional context information.</param>
/// <returns>A UITypeEditorEditStyle value that indicates the style of editor used by EditValue.</returns>
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
// The listbox is a drop down control.
if (context != null && context.Instance != null)
{
return UITypeEditorEditStyle.DropDown;
}
return base.GetEditStyle(context);
}
#endregion
}
}
There you go 
|
|
|
|
|
I've not yet started working on .NET so just want to clarify a primary concept about .NET by asking question here.
Friends, in programming with Visual C++ 6, we deal directly Windows Operating systems API. For example consider Winsock API available with operating system. Whenever there is a need to write an application that connects to other systems on a network, we use Winsock API functions to do so. Microsoft made our life easy by encapsulating various Winsock API calls in MFC classes. These MFC socket classes do nothing more than making our life easy. These classes are just the wrapper around same Winsock API functions that we were using before.
I like to ask you the role of .NET in this case. In .NET there are also Socket classes which according to many people are much better than MFC socket classes. Now what is the role of .NET in this case. Here is my question:
Is the role of .NET socket classes same as that of MFC. I mean are .NET classes internally calling the same native Operating system APIs just like MFC ??
|
|
|
|
|
Most likely yes. In most cases, the .NET Base Class Library uses the same API's that you would use in C++.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Shah Shehpori wrote:
Is the role of .NET socket classes same as that of MFC. I mean are .NET classes internally calling the same native Operating system APIs just like MFC ??
Yes, but they have a much more modern design, and are much easier to write. The design goal seemed to be "the user of these classes should only need to get into detail if he needs to get into detail".
ORACLE One Real A$#h%le Called Lary Ellison
|
|
|
|
|
Hi!
i think i have a problem with .net framework. There is a resourceviewer called reflector. whenn i start it i get an errormassage:
the following assembly name can't be resolved automatically:
System.Windows.Forms.resources, Version=1.0.5000.0, Culture=de-DE, PublicKeyToken=b77a5c561934e089
please select the assembly file manually.
i reinstalled the framework sdk and the framework redist (both v 1.1). but the error is still comming.
what's wrong? please help.
misch
|
|
|
|