|
below string is saved in database.
<people>
<user>
<id>1</id>
<name>홍</name>
</user>
<user>
<id>2</id>
<name>김</name>
</user>
</people>
I want to read xml's contents by using XmlTextReader.
but There is no xml file just saved into database.
How can i read?
hi
My english is a little.
anyway, nice to meet you~~
and give me your advice anytime~
|
|
|
|
|
Finally figured it out!
Suppose you get the above string, lets name it as xmlBody.
Next step will be to create a proper xml.
String CompleteXml="<xml version=\"1.0\"?>" + xmlBody;
Now to read using XmlTextReader, StringReader is the solution that i found.
Here is how it goes :
XmlTextReader reader=new XmlTextReader(new System.IO.StringReader(CompleteXml));
Now you can read it.
By the way, using XmlTextReader is a good choice of yours as it is fast and suitable for Large Xml files.
People with high attitude deserve the standing ovation of our highest finger!
My Technical Blog![ ^]
modified on Monday, March 14, 2011 5:48 AM
|
|
|
|
|
Hi,
I tried with below code and i'm getting only root directories not sub directories , i need to get sub directories
please suggest me better way.
string ftpServerIP = "75.125.2.193";
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://" + ftpServerIP + "/");
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
request.Credentials = new NetworkCredential("barikgr2", "barik122");
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
string line;
while ((line = reader.ReadLine()) != null)
{
TreeNode node = new TreeNode();
string[] _arv = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
node.Text = _arv[3];
treeView1.Nodes.Add(node);
}
reader.Close();
response.Close();
Regards,
Vishnu.
|
|
|
|
|
|
Hi,
I'm trying to make a program for booking rooms in my school library automatically. I need a way to check if a certain ID/password is valid on the domain because library uses network credentials. My laptop is on school's domain and it doesn't have admin rights. I tried googling this problem, many people suggested using DirectoryServices, but for some reason when I include this namespace then I get error message saying "Namespace is not valid". Any help will be appreciated.
Shivam
|
|
|
|
|
I suggest you try this:
1.
in the solution pane, add a reference to your project, use .NET tab, locate "System.DirectoryServices"
2.
in your source file(s), add a line using System.DirectoryServices;
And you may have to repeat the same for System.DirectoryServices.AccountManagement (which exists since .NET 3.5)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Ya I figured that out before your replied.
I tried using method find on internet to authenticate. This is exception I'm getting
System.DirectoryServices.AccountManagement.PrincipalServerDownException was unhandled
Message=The server could not be contacted.
Source=System.DirectoryServices.AccountManagement
I used following code.
PrincipalContext adContext = new PrincipalContext(ContextType.Domain);
bool valid;
using (adContext)
{
valid = adContext.ValidateCredentials("studentID", "password");
}
Console.Write(valid);
What I'm doing wrong here. And is it even possible to validate, because I'm not an admin of domain.
|
|
|
|
|
I don't really know.
I read your question once more, and now I strongly doubt Windows would allow a non-admin to query the user/password list like that. It would support a brute force attack and hence constitute a security risk.
You may have to rethink your authentication approach; maybe the user being logged on and running your app is sufficient; or your app should rely on its own authentication (i.e. your own user list in the database).
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Luc Pattyn wrote: You may have to rethink your authentication approach; maybe the user being
logged on and running your app is sufficient; or your app should rely on its own
authentication (i.e. your own user list in the database).
Indeed. Why query anything?
If the machines require a domain account to log onto them, and they are logged on, the username and password were valid.
|
|
|
|
|
Thank you for replying.
So basically, right now my program as 15 IDs and password in its data base. I've added a button "contribute" where other students could donate their ID and passwords, these ID and passwords are their credentials on school's domain, also it is used to authenticate the library booking. I need some way to validate this, I first tried to validate using HTTPrequest and directly validating it through logging into library, if error occurs then credentials are not valid. This approach is kind of hard, I found that there is some __ISVALID post parameter that keeps changing, so first I've to parse source to find this parameter then and logging then check its validity. Therefore, I switched to this approach, of checking credential within active directory. Now, this seems not to work either..I wonder, in my laptop I could logging with my friend's network ID and password, so there should to be some way of just VALIDATING the credentials, not tampering it. Or could think of some other way???
Shivam
|
|
|
|
|
VERY bad practice, storing passwords. Maybe store a hash of a password to compare with the original, but the password itself? The network people would have a hissy fit.
Also, what are you going to do in 90 or 180 days when everyone changes their network password and it no longer matches what you have in the database?
I think you missed the point. If the computers you are concerned about are on in the domain the network, and they require a user to log in to use them, then the authentication has already taken place and you don't really need to do anything else.
|
|
|
|
|
What?? It is just a hobby project, our school library is always packed, but there is a system which allows you to book rooms exactly at 10:00 AM in morning, it requires three people to log in and book the room..so me and my friends have decided to make a program that can do this automatically for us..its not a large scale program where people would keep changing their IDs and Password..
|
|
|
|
|
Are you sure about the code you are using? I Googled and found similar, but they had
PrincipalContext(ContextType.Domain, Domain)
not
PrincipalContext(ContextType.Domain)
|
|
|
|
|
I see..I solved the problem..I'm happy.
I used c sharp in build browser control..it is damn easy. You can find any HTML input element using document thingy..then insert some value in it..and click on button..and search if error occurs..Microsoft is best..c sharp rocks..
|
|
|
|
|
I have created tab control with 5 tabs on a form. How can I draw or override onpaint() inside the area of any of the tabs?
Thanks
|
|
|
|
|
A TabControl holds one or more TabPages or TabPage derivatives. They get painted (well, the one that is current) just like any other Control. You either override their OnPaint() or add your paint handler to its Paint event.
The one thing that seems to puzzle a lot of users is the tabs themselves are drawn by the TabControl, not the TabPages, and can't be changed much through properties; if you want the tabs to look different, search the CP articles, there are a couple on that particular subject.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
I believe you will need to subclass TabPage and override OnPaint in there to provide your own drawing. Alternatively handle each TabPage 's Paint event.
|
|
|
|
|
I am a newbie to C#. I am having hard time with subclassing the tabpage I guess. Is there any example or psuedo code that I can look at?
Thanks
|
|
|
|
|
Sure...
using System;
using System.Drawing;
using System.Windows.Forms;
namespace YourNamespace
{
public class CustomTabPage : TabPage
{
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
}
}
}
Instead of adding the standard TabPages to your TabControl, add these (once you have rebuilt your project it will appear in your toolbox).
|
|
|
|
|
hi guys
i write gps info into image but not display
whats problem
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
Image Pic;<br />
PropertyItem[] PropertyItems;<br />
<br />
string FilenameTemp;<br />
System.Drawing.Imaging.Encoder Enc = System.Drawing.Imaging.Encoder.Transformation;<br />
EncoderParameters EncParms = new EncoderParameters(1);<br />
EncoderParameter EncParm;<br />
ImageCodecInfo CodecInfo = GetEncoderInfo("image/jpeg");<br />
<br />
double dLat = 38.00000000000;<br />
double dLong = 48.0000000000;<br />
string Filename = "E:\\001.jpg";<br />
byte[] bLat = BitConverter.GetBytes(dLat);<br />
byte[] bLong = BitConverter.GetBytes(dLong);<br />
<br />
Pic = Image.FromFile(Filename);<br />
<br />
PropertyItems = Pic.PropertyItems;<br />
PropertyItems[0].Id = 0x0002;<br />
PropertyItems[0].Type = 5;<br />
PropertyItems[0].Len = bLong.Length;<br />
PropertyItems[0].Value = bLong;<br />
Pic.SetPropertyItem(PropertyItems[0]);<br />
<br />
PropertyItems = Pic.PropertyItems;<br />
PropertyItems[0].Id = 0x0004;<br />
PropertyItems[0].Type = 5;<br />
PropertyItems[0].Len = bLat.Length;<br />
PropertyItems[0].Value = bLat;<br />
Pic.SetPropertyItem(PropertyItems[0]);<br />
<br />
FilenameTemp = Filename + ".temp";<br />
<br />
EncParm = new EncoderParameter(Enc, (long)EncoderValue.TransformRotate90);<br />
EncParms.Param[0] = EncParm;<br />
<br />
Pic.Save("e:\\0001.jpg", CodecInfo, EncParms);<br />
<br />
<br />
}<br />
private static ImageCodecInfo GetEncoderInfo(String mimeType)<br />
{<br />
int j;<br />
ImageCodecInfo[] encoders;<br />
encoders = ImageCodecInfo.GetImageEncoders();<br />
for (j = 0; j < encoders.Length; ++j)<br />
{<br />
if (encoders[j].MimeType == mimeType)<br />
return encoders[j];<br />
}<br />
return null;<br />
}<br />
thanks a lot
|
|
|
|
|
There is an article on an Exif library here on CodeProject:
ExifLibrary for .NET[^]
Perhaps that might help you - I had to change some code for updating GPS values, but according to the author that should already be fixed now.
|
|
|
|
|
Hello.
I have a programm that scans the selected folder and adds all the files' names to the listbox.
I'm running the scan function in a separate thread. But, still the main form is freezing.
Here is my code:
private void button2_Click(object sender, EventArgs e)
{
Thread mThread = new Thread(myThread);
myThread.Start();
}
public void myThread()
{
AddFiles(label1.Text);
}
public void AddFiles(string targetDirectory)
{
if (listBox1.InvokeRequired)
{
AddFilesAdd method = new AddFilesAdd(AddFiles);
listBox1.Invoke(method, new object[] { targetDirectory });
return;
}
if (progressBar1.InvokeRequired)
{
AddFilesAdd method = new AddFilesAdd(AddFiles);
progressBar1.Invoke(method, new object[] { targetDirectory });
return;
}
string[] fileEntries = Directory.GetFiles(targetDirectory);
foreach (string fileName in fileEntries)
{
this.listBox1.Items.Add(fileName);
progCounter++;
progressBar1.Value = progCounter;
}
string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
foreach (string subdirectory in subdirectoryEntries)
{
numberOfFolders++;
AddFiles(subdirectory);
}
|
|
|
|
|
Hi,
your code looks a bit weird to me. Here are some comments:
1.
AddFiles(label1.Text); is strictly not OK, you are touching a Control from a thread other than the main one. A better approach is to read label1.Text before launching the thread, then pass the string to it somehow (class member, or ThreadStart parameter).
2.
the progressbar code will never execute: progressBar1.InvokeRequired and listBox1.InvokeRequired are bound to have the same value, so either the first if block's return will fire, or both if blocks will be skipped.
3.
the whole threading approach is flawed: there really isn't any code running on the separate thread, all it does is cause the outermost AddFiles() to run on the main thread, so the hierarchical scan is all on the main thread (which will be very busy and uncapable of serving the GUI).
Solution: split the action in two parts, the first part scanning the file system and storing strings in a collection (all on the separate thread), the second part adding the collection's content to the ListBox.
4.
Lastly, this is a typical job a BackgroundWorker is good at. It would do the scanning in the DoWork handler, and the ListBox updating in the RunWorkerCompleted handler. You wouldn't need to call Invoke at all, the BGW does that for you.
PS: you may want to read this my little article[^] on the matter.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
how read and write from/to stream color and points of line
|
|
|
|
|
I guess you need a BinaryWriter[^].
I must get a clever new signature for 2011.
|
|
|
|