|
There is as I remember an article on that here on CP. Many moons back.
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
When I try to generate an xml file with StringWriter, I can’t change the encoding (UTF-16) to UTF-8. This application, having to have a format xml(utf-8) To preserve compatibility with other programs.
Ex
StringWriter s = new StringWriter();
XmlTextWriter tw = new XmlTextWriter(s,Encoding.UTF-8);
Don’t work, I am receive a error message “C:\Inetpub\wwwroot\LicenceTools\site\GenerateXmlTreeView.aspx.cs(58): Argument '1': cannot convert from 'System.IO.StringWriter' to 'System.IO.Stream'”
I would like having "?xml version="1.0" encoding="utf-8"?" rather than "?xml version="1.0" encoding="utf-16"?"
Could you help me?
Thanks in advance
PS: It s a stream for WebServer.
Application Code:
Htm:
<%@ Page language="c#" Codebehind="GenerateXmlTreeView.aspx.cs" AutoEventWireup="false" Inherits="LicenceTools.site.GenerateXmlTreeView" %>
C#:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using ZZDataFromDb.ZZConn;
using ZZTools.ZZTools;
using System.Xml;
using System.IO;
using System.Globalization;
using System.Text;
using System.Xml.XPath;
namespace LicenceTools.site
{
///
/// Summary description for GenerateXmlTreeView.
///
public class GenerateXmlTreeView : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
//StringReader = new StreamReader("site/GenerateXmlTreeView.aspx");
string strSelect;
// Put user code to initialize the page here
if( Request.QueryString["select"] != null)
{
strSelect =Request.QueryString["select"];
}else {
strSelect= "";
}
string strIdCompany;
if( Request.QueryString["IdCompany"] != null)
{
strIdCompany =Request.QueryString["IdCompany"];
}
else
{
strIdCompany= "%";
}
DataContainer dc=new DataContainer(); // create a data container for this function
dc.Set("select", strSelect); // add the user name
dc.Set("IdCompany", strIdCompany); // add the user name
DBData dts=new DBData(dc); // create a interface to the DB technology
DataTable DT;
DT = dts.QueryMultiRow("sql_fillTreeView"); // query if the account exists. Always returns a value
//Xml Generate
ArrayContainer Level = new ArrayContainer(100);
StringWriter s = new StringWriter();
//string test = s.Encoding.ToString();
XmlTextWriter tw = new XmlTextWriter(s);// ,Encoding.UTF8
tw.Formatting=Formatting.Indented;
tw.WriteStartDocument();
tw.WriteStartElement("treeview");
tw.WriteAttributeString("title","Licenses Tool");
tw.WriteStartElement("custom-parameters");
tw.WriteStartElement("param");
tw.WriteAttributeString("name","shift-width");
tw.WriteAttributeString("value","15");
tw.WriteEndElement();
tw.WriteStartElement("param");
tw.WriteAttributeString("name","img-directory");
tw.WriteAttributeString("img-directory","images/");
tw.WriteEndElement();
tw.WriteEndElement();
int level=0;
string IdElement;
Level.add("");
string Name;
string IdPrduit;
string IdParent;
string License;
string PrevIdParent="";
string PrevIdElement="";
bool FlagElementFirst= true ;
foreach(DataRow r in DT.Rows){
if (FlagElementFirst == true)
{
Level.Remove(0);
Level.add(r["idParent"].ToString());
}
IdElement = r["id"].ToString();
Name = r["Name"].ToString();
IdPrduit = r["IdPrduit"].ToString();
IdParent = r["idParent"].ToString();
License = r["license"].ToString();
if(( Level[IdParent]>=level ||level==0 ))
{
if((IdParent=="" || IdParent!=PrevIdParent ) && (IdPrduit=="") )
{
Console.WriteLine("Name");
tw.WriteStartElement("folder");
tw.WriteAttributeString("title",Name);
if (FlagElementFirst == true)
{
tw.WriteAttributeString("img","folder");
}
else
{
tw.WriteAttributeString("img","folder");
}
level++ ;
Level.add(IdElement);
PrevIdParent=IdParent;
PrevIdElement =IdElement;
}
else if((IdParent==PrevIdParent)&& IdParent!="" && (IdPrduit=="") )
{
}
else if(IdPrduit!="")
{
string reg;
if(License=="Y") {reg="true";}
else {reg="false" ; }
tw.WriteStartElement("leaf");
tw.WriteAttributeString("title",Name);
tw.WriteAttributeString("url", IdElement);
tw.WriteAttributeString("registered",reg);
tw.WriteEndElement();
//tw.WriteAttributeString("test","test");
}
}
else
{
while(level>Level[IdParent])
{
tw.WriteEndElement();
Level.Remove(level);
level--;
}
if(IdPrduit !="")
{
//tw.WriteElementString(Name,IdPrduit);
string reg;
if(License=="Y") {reg="true";}
else {reg="false" ; }
tw.WriteStartElement("leaf");
tw.WriteAttributeString("title",Name);
tw.WriteAttributeString("url",IdElement);
tw.WriteAttributeString("registered",reg);
tw.WriteEndElement();
}
else
{
tw.WriteStartElement("folder");
tw.WriteAttributeString("title",Name);
tw.WriteAttributeString("img","folder.gif");
Level.add(IdElement);
PrevIdParent=IdParent;
PrevIdElement =IdElement;
level++;
}
}
FlagElementFirst = false;
}
tw.WriteEndDocument();
tw.Flush();
tw.Close();
Response.Clear();
Response.ContentEncoding = Encoding.UTF8;//
//Encoding.GetEncoding(1251) ;
Response.ContentType="text/xml";
Response.Write(s.ToString());
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
-=zoltx=-
|
|
|
|
|
using System.IO;
using System.Xml;
MemoryStream ms = new MemoryStream();
XmlTextWriter tw = new XmlTextWriter(ms,new System.Text.UTF8Encoding());
tw.WriteStartDocument();
tw.WriteStartElement("...");
tw.WriteEndElement();
tw.WriteEndDocument();
tw.Flush();
tw.Close();
String s = System.Text.Encoding.UTF8.GetString( ms.GetBuffer() );
MessageBox.Show( s );
|
|
|
|
|
Thanks a lot. It works..... somebody, send me an others solution which work too
public class StringWriterWithEncoding : StringWriter
{
Encoding encoding;
public StringWriterWithEncoding (Encoding encoding)
{
this.encoding = encoding;
}
public override Encoding Encoding
{
get { return encoding; }
}
}
Then you'd do:
XmlTextWriter = new XmlTextWriter
(new StringWriterWithEncoding (Encoding.UTF8));
-=zoltx=-
|
|
|
|
|
I have to admit the StringWriter derived class is a much better approach to the encoding issue. Use it instead of the C-like memory streams I have suggested.
|
|
|
|
|
You are great ........ Thanks a lot ......
-=zoltx=-
|
|
|
|
|
Hello,
Is there a way a class can access private and protected members of another class? Like friend keyword in C++. I haven't discovered it.
Thanks!
Best regards,
Alexandru Savescu
P.S. Interested in art? Visit this!
|
|
|
|
|
Alexandru,
a similar construct to friend is the internal keyword, which allows access from within the same assembly, but not from outside.
Wolfgang
|
|
|
|
|
Thanks for the reply.
However the protected members I wanted to access were some WebControls that the designer created for me in a ASP.NET page. I didn't want to manually change the access level for those object so I decided to redesign my application.
Best regards,
Alexandru Savescu
P.S. Interested in art? Visit this!
|
|
|
|
|
I am creating a custom control which inherits from combobox class.
Now, I want to prevent some events from being occured at special times, for example I want my combobox, when is in droped down state, not responsing to click events, to prevent it from getting back to its default state. I think it may be done throughout overriding OnClick eventhandler or some better one to handle.
Please help me!
Regards
|
|
|
|
|
Meisi wrote:
I think it may be done throughout overriding onclick
Correct, more specifically override OnClick and in the cases where you don't want the Click event to fire just don't call base.OnClick() . Then when you want the Click event to fire ensure you call base.OnClick() .
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Have you any suggestion exactly about this :
"I want my combobox, when is in droped down state, not responsing to events, to prevent it from getting back to its default state"
The OnClick is not proper for this situation.
Regards
|
|
|
|
|
Is there way to make int i = (int)3.6; give a rounded as opposed to floored result? Some global setting?
|
|
|
|
|
|
Don't know about anyone else, but I can't see it listed as a namspace from the VisualStudio .NET IDE!!!!!
Help!!!!
Where is it. Can't see it at work on my NT4 box or at home on my Win2K box.
Its not there!!!!
Anyone know why?
Quote from a clever bloke :
"I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein
|
|
|
|
|
Right click on the 'References' tree node in the project view. Goto 'Add Reference', then look down the .NET list for System.EnterpriseServices, click select then OK.
You can now use the namespace in your code. Howzzat!
"De most compwehensive image seawch on de web." - Google in Elmer Fudd Language "But a fresh install - it's like having clean sheets" - Chris Maunder Lounge 3 Mar '03
Jonathan 'nonny' Newman Web Designer, Programmer, Lover, Visionary Leader...
Homepage [www.nonny.com] [^]
|
|
|
|
|
Okay. I'm slow of the mark today.
Thanks,
Giles
Quote from a clever bloke :
"I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein
|
|
|
|
|
(Precursor)
http://www.codeproject.com/cs/menu/dockingcontrol.asp?target=dockstyle%7Csize
discusses adding controls to a form using AddRange in a specific order.
(The problem)
I am trying to do the following, dynamically in a form constructor:
1. Add TabControl to form. TabControl is set to DockStyle=Fill
2. Add TabPage to TabControl. (Automatically fills TabControl)
3. Add Panel to TabControl.
Problem: I need to access the size of the TabPage AFTER the DockStyle=Fill has come into effect. This is to precisely position the panel in a location on the TabPage.
But during initialization, the only Width/Size I can get from TabPage, is the DefaultSize (100 x 200)
Is there any command I can call to force the TabControl to fill the parent form, then retrieve the new size/width of the contained TabPage after the fill?
Thanks for suggestions.
|
|
|
|
|
Use Load or Resize event of controls (panel etc)
Hi,
AW
|
|
|
|
|
Hi
Thanks for reply. However it still seems no clearer. I also found a Layout event.
The question is: At what time, during the instantiation of a control, can we be certain that the DockStyle Fill has been applied to the controls width/height. And therefore, at that point, we can be certain to rely on those as containing the final values, and not the DefaultSize values?
MSDN seems unclear on this in any of the event descriptions.
Cheers
|
|
|
|
|
I have a Treeview/Listview pair in a Windows Form that behaves like Windows Explorer, displaying folders and files on my machine... both controls have checkboxes for each entry so I can keep track of what's been selected.
Aside from maintaining a current global TreeViewEventArgs object, is there a good way to update the Treeview when you click the listview and receive the listview_AfterCheck event? I want to be able to have the parent (folder) node in the treeview become "checked" when I "check" a file in the list view... wondering if the .NET framwork provides some sort of communication mechanism for this..???
thanks.
|
|
|
|
|
Since a form hosts both the treeview and the listview, I would override both OnBeforeCheck event handlers, and provide a default implementation to them, calling a unique method at the form level. This method in turn Invokes Check() methods exposed by tree nodes, and list nodes.
Nothing really new to talk about, that's much like delegating the application logic to a control manager.
|
|
|
|
|
Interesting, I guess I've never overridden a windows-fired event... how do you get windows to fire the overridden vs. the non-overridden event?
thanks.
|
|
|
|
|
Silly question probably, but...Whats the easiest way to communicate from a child Window to a parent window. For example, when the app starts, I want a login form to popup. When entered, that data needs to be available throughout the app. Currently I am using the "OnMdiChildActivate" event on the parent window which works, but it seems as if there should be a better way.
Cody C
|
|
|
|
|
You could do this in a couple of ways.
If you are in full control of the form that is poping up, you can get the required information by capturing the OnClosing event of the logon form, add the event handler in your MDI parent's load event when you open the mdi child:
LogonForm f = new LogonForm();
f.MdiParent = this;
f.OnClosing += new EventHandler(this.Form1_Closing);
Having done this, write code along these lines to capture properties from the closing logon form:
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
LogonForm f = (LogonForm)sender;
string Uname = f.Username;
string Pword = f.Password;
}
obviously you'll need to set up properties such as Username & Password in you logon form that are public.
An other way may be to pass up a custom Logon class from the Parent to the child by reference, you can then populate it from the logon form and the information will be available to the parent.
Let me know if you'd like me to elaborate on either of these methods.
|
|
|
|