|
thanks for your reply. I've tried to do that method, but i got problem in parse the string. The string has a blank space delimiters. But, when i use this code, the string can't be splitted. Thanks for your help
string line = "";
string[] fields = null;
string errorInfo = String.Empty;
this.openFileDialog1.ShowDialog();
if (!(this.openFileDialog1.FileName == null))
this.textBox3.Text = this.openFileDialog1.FileName;
string txt = this.textBox3.Text;
DataTable tbl = new DataTable("InputFile");
try
{
using (StreamReader sr = new StreamReader(txt))
{
// first line has headers
if ((line = sr.ReadLine()) != null)
{
fields = line.Split(new char[] { '\x20', '\x20' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string s in fields)
{
tbl.Columns.Add(s);
}
}
else
{
// it's empty, that's an error
throw new ApplicationException("The data provided is not in a valid format.");
}
// fill the rest of the table; positional
while ((line = sr.ReadLine()) != null)
{
DataRow row = tbl.NewRow();
fields = line.Split(new char[] { '\x20', '\x20' }, StringSplitOptions.RemoveEmptyEntries);
int i = 0;
foreach (string s in fields)
{
row[i] = s;
i++;
}
tbl.Rows.Add(row);
}
}
}
catch (Exception)
{
throw new ApplicationException("There was an error attempting to read the data. Please verify the data provided is in a valid format, is tab-delimited text, and includes only ONE header line.");
}
//return tbl;
this.dataGridView1.DataSource = tbl;
|
|
|
|
|
I am assuming that the '\' are the seperators. Here is the code:
string[] values = null;
using (DataTable dt = new DataTable())
{
using (OpenFileDialog ofd1 = new OpenFileDialog())
{
DialogResult diagR = ofd1.ShowDialog();
if (diagR == DialogResult.Cancel)
return;
using (StreamReader sr = new StreamReader(ofd1.FileName))
{
sr.BaseStream.Seek(0, SeekOrigin.Begin);
bool headerLine = true ;
while (!sr.EndOfStream)
{
values = sr.ReadLine().Split(Convert.ToChar(@"\"));
if (headerLine)
{
foreach (string s in values)
{
dt.Columns.Add(s);
headerLine =false ;
}
}
else
{
DataRow dr = dt.NewRow();
for (int i = 0; i < values.Length; i++)
{
if (i > dt.Columns.Count - 1)
break;
dr[dt.Columns[i].ColumnName] = values.GetValue(i).ToString();
}
dt.Rows.Add(dr);
dt.AcceptChanges ();
}
}
}
}
}
|
|
|
|
|
|
Don't give all the data as that's just stoopid.
What have you tried? There are a dozen ways to do this using the .net framework that I can think of. Have a go, then when you get stuck come back, on this thread, and tell us why you can't read in a single line or split it into tokens.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Hi Fellows
Thanx for the help you provided.
now let me ask you another doubt,I hope i'll get solved it quick.
1.i am working(programming)with visual studio 2005.
2.how to change the deployment aspects according to my likeness.
3.In Detail: How to change the place of bitmap and buttons in installation windows.
4.how to change progressbar style/color in installation windows.
Please give me any link that desribs abt Visual studiol deployment specifying the graphical modules
|
|
|
|
|
hi i am trying to retrieve data from access databases multiple tale into a dataset, with dataset iam trying to populate the crystal report of C#. but after doing all this procedure the data is displayed multiple times. i dont know where i have gone wrong. can any one help me out of this.
the code written is as follows
namespace ContractSystem
{
public partial class ViewPSDClrdReport : Form
{
OleDbConnection con;
OleDbDataAdapter da,da1;
OleDbCommand cmd,cmd1;
OleDbDataReader rd,rd1;
DataSet ds;
DataTable dt;
PSDClrdCrystalReport rpt;
string str1, str2, str3,str4;
public ViewPSDClrdReport(string s1,string s2,string s3)
{
InitializeComponent();
str1 = s1;
str2 = s2;
str3 = s3;
}
private void ViewPSDClrdReport_Load(object sender, EventArgs e)
{
crystalReportViewer1.DisplayGroupTree = false;
try
{
con = new OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0; Data Source=e:/Ashish/Practice/ContractSystem/ContractSystem/ContractSystemDB.mdb");
con.Open();
ds = new DataSet();
rpt = new PSDClrdCrystalReport();
if (str3 == "All")
{
cmd = new OleDbCommand("select PrNo from PSDApproval where FwdDtByPSD between '" + str1 + "' and '" + str2 + "'", con);
rd = cmd.ExecuteReader();
if (rd.HasRows)
{
while (rd.Read())
{
str4 = rd.GetString(0);
da = new OleDbDataAdapter("select PrNo,Description,ValueQuoted,PurchaseGrp,RcdDtEA,FwdDtPSD,Initial from InitialApproval where InitialApproval.PrNo='" + str4 + "'", con);
da.Fill(ds, "InitialApproval");
da.Dispose();
da1 = new OleDbDataAdapter("select EstimatedVal,FwdDtByPSD from PSDApproval where PSDApproval.PrNo='" + str4 + "'", con);
da1.Fill(ds, "PSDApproval");
da1.Dispose();
MessageBox.Show("ALL ADDED");
}
}
//rpt.SetDataSource(ds);
}
else
{
cmd = new OleDbCommand("select PrNo from PSDApproval where FwdDtByPSD between '" + str1 + "' and '" + str2 + "'", con);
rd = cmd.ExecuteReader();
if (rd.HasRows)
{
while (rd.Read())
{
str4 = rd.GetString(0);
cmd1 = new OleDbCommand("select PurchaseGrp from InitialApproval where PrNo='" + str4 + "'", con);
rd1 = cmd1.ExecuteReader();
if (rd1.HasRows)
{
while (rd1.Read())
{
string t = rd1.GetString(0);
if (t == str3)
{
da = new OleDbDataAdapter("select PrNo,Description,ValueQuoted,PurchaseGrp,RcdDtEA,FwdDtPSD,Initial from InitialApproval where InitialApproval.PrNo='" + str4 + "'", con);
da.Fill(ds, "InitialApproval");
da.Dispose();
da1 = new OleDbDataAdapter("select EstimatedVal,FwdDtByPSD from PSDApproval where PSDApproval.PrNo='" + str4 + "'", con);
da1.Fill(ds, "PSDApproval");
da1.Dispose();
MessageBox.Show("GRP ADDED");
//rpt.SetDataSource(ds);
}
}
}
}
}
}
rpt.SetDataSource(ds);
crystalReportViewer1.ReportSource = rpt;
MessageBox.Show("Record Added To Report");
}
catch (Exception ex)
{
MessageBox.Show("Error" + ex);
}
finally
{
con.Close();
}
}
}
}
|
|
|
|
|
what is c# object graphs? plz can any1 tell me in detail.
thanks.
|
|
|
|
|
|
`hi want to make an ip messenger can i get the information about the project or can anybody help to getting the codes fro the project
>
|
|
|
|
|
Start reasearching/writing your project.
Come back here when you have an actual problem/question.
As I'm feeling generous I'll give you a hint for the first bit of Googling you'll do.[^]
hmmm pie
|
|
|
|
|
i almost search google from past 3 hours and i did not get nay good information
|
|
|
|
|
shomic.goyal wrote: i almost search google
How can you almost search Google?
Anyway, what were you Googling?
hmmm pie
|
|
|
|
|
case study for making an ip messenger
|
|
|
|
|
You're not just going to be able to find out how to do it by just copying someone else!
You have to search for the building blocks and put them together yourself! If you can't figure out how to do it then I suggest going back a few steps and picking up the basics.
By the way, I found a 'case study' and it was the top result of my first Google.
Edit: Make that multiple 'case studies' with the same search.
hmmm pie
|
|
|
|
|
that case study i read it but it will not help it to me
|
|
|
|
|
What case study? I didn't link you.
Anyway, you should look at it and see how you can adapt it to suit your needs.
hmmm pie
|
|
|
|
|
see what happen when you feed a troll?
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
They go and throw up, so they can stay thin.
hmmm pie
|
|
|
|
|
fly904 wrote: They go and throw up, so they can stay thin.
As soon as I saw your post, I thought of "Die...Die...Die" as in troll die... then I saw your signature.
fly904 wrote: hmmm pie
hmmmm die....die....die...
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
you have no freaking clue. Now put down your research paper and apply at your nearest fast food resturant.
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
Hello, I have been working on a application to help us better manage our network. The application is for myself and one other person at our agency. Everything is working fine, but doing this one thing (getting list of users) from LDAP remotely is very slow. Now I know it will be slower than normal, but how I have coded it might freak some of you out, and see how I could make what I am trying to do quicker.
I have used alot of the LDAP/AD coding from an article on this site (codeproject).
Thanks to:
http://www.codeproject.com/KB/system/everythingInAD.aspx[^]
First,
I have a ListView control that populates with every user. Every user has a icon (man icon) that either has a lock symbol (if the user is locked), a X symbol on it (if the user is disabled), or nothing if the user does not have either one of those.
1. Here is what it is doing when Adding to the ListView Control:
private delegate void AddListItemDelegate();
void AddListItem()
{
if (listViewUsers.InvokeRequired)
{
listViewUsers.Invoke(new AddListItemDelegate(AddListItem));
}
else
{
if (!UseAuth) adPrincipalContext = new PrincipalContext(ContextType.Domain, Properties.Settings.Default.LDAP);
else adPrincipalContext = new PrincipalContext(ContextType.Domain, Properties.Settings.Default.LDAP,
(string)Encoding.Unicode.GetString(Convert.FromBase64String((string)Properties.Settings.Default.LDAPusername)),
(string)Encoding.Unicode.GetString(Convert.FromBase64String((string)Properties.Settings.Default.LDAPpassword)));
UserPrincipal user = new UserPrincipal(adPrincipalContext);
user.Name = "*";
PrincipalSearcher pS = new PrincipalSearcher();
pS.QueryFilter = user;
PrincipalSearchResult<Principal> results = pS.FindAll();
listViewUsers.Items.Clear();
ListViewItem listItem;
foreach (Principal result in results)
{
AD newAD = new AD(result.Name);
bool Locked = newAD.IsLocked();
bool Enabled = newAD.IsEnabled();
string Branch = newAD.branch;
listItem = new ListViewItem(result.Name);
listItem.ToolTipText = "Sid: " + result.Sid;
if (Enabled)
{
if (Locked) listItem.ImageIndex = 1;
else listItem.ImageIndex = 0;
}
else listItem.ImageIndex = 2;
bool found = false;
if (String.IsNullOrEmpty(Branch)) Branch = "Unknown";
foreach (ListViewGroup g in listViewUsers.Groups)
{
if (g.Header == Branch) {
found = true;
listItem.Group = g;
break;
}
}
if (!found)
{
ListViewGroup g = new ListViewGroup(Branch, Branch);
listViewUsers.Groups.Add(g);
listItem.Group = g;
}
listViewUsers.Items.Add(listItem);
}
}
}
So what I have this doing is getting a list of users from AD, but also going to my AD class to see if the user is LOCKED or DISABLED. This is what is happening behind the AD class:
try
{
using (DirectoryEntry root = new DirectoryEntry())
{
root.Path = LDAP;
if (UseAuth)
{
root.Username = (string)Encoding.Unicode.GetString(Convert.FromBase64String((string)Properties.Settings.Default.LDAPusername));
root.Password = (string)Encoding.Unicode.GetString(Convert.FromBase64String((string)Properties.Settings.Default.LDAPpassword));
}
using (DirectorySearcher searcher = new DirectorySearcher())
{
searcher.SearchRoot = root;
searcher.SearchScope = SearchScope.Subtree;
searcher.Filter = "(&(objectClass=user)(name=" + this.userName + "))";
searcher.PropertiesToLoad.Add("mail");
searcher.PropertiesToLoad.Add("department");
searcher.PropertiesToLoad.Add("company");
searcher.PropertiesToLoad.Add("physicalDeliveryOfficeName");
searcher.PropertiesToLoad.Add("telephoneNumber");
SearchResultCollection results = searcher.FindAll();
if (results != null)
{
foreach (SearchResult result in results)
{
ResultPropertyCollection props = result.Properties;
foreach (string propName in result.Properties.PropertyNames)
{
if (propName == "mail") mail = props[propName][0].ToString();
else if (propName == "department") branch = props[propName][0].ToString();
else if (propName == "company") division = props[propName][0].ToString();
else if (propName == "physicalDeliveryOfficeName") office = props[propName][0].ToString();
else if (propName == "telephoneNumber") officenumber = props[propName][0].ToString();
else if (propName == "adspath") adspath = props[propName][0].ToString();
}
}
}
searcher.Dispose();
root.Close();
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
So what I am doing here is using the username provided from the previous class and passing it to here to set the username and password. If you look in the previous code you will see this:
AD newAD = new AD(result.Name);
bool Locked = newAD.IsLocked();
bool Enabled = newAD.IsEnabled();
The code I have for checking if it is locked:
public bool IsLocked()
{
try
{
DirectoryEntry uEntry;
if (UseAuth) uEntry = new DirectoryEntry(this.adspath, (string)Encoding.Unicode.GetString(Convert.FromBase64String((string)Properties.Settings.Default.LDAPusername)), (string)Encoding.Unicode.GetString(Convert.FromBase64String((string)Properties.Settings.Default.LDAPpassword)));
else uEntry = new DirectoryEntry(this.adspath);
bool Locked = Convert.ToBoolean(uEntry.InvokeGet("IsAccountLocked"));
uEntry.Close();
if (Locked) return true;
else return false;
}
catch (DirectoryServicesCOMException ex)
{
return false;
}
}
and
public bool IsEnabled()
{
DirectoryEntry uEntry;
if (UseAuth) uEntry = new DirectoryEntry(this.adspath, (string)Encoding.Unicode.GetString(Convert.FromBase64String((string)Properties.Settings.Default.LDAPusername)), (string)Encoding.Unicode.GetString(Convert.FromBase64String((string)Properties.Settings.Default.LDAPpassword)));
else uEntry = new DirectoryEntry(this.adspath);
int val = (int)uEntry.Properties["userAccountControl"].Value;
uEntry.Close();
if (val == (val & ~0x2)) return true;
else return false;
}
So basically what I am doing is querying LDAP, getting a list of users, then going through each user and querying LDAP AGAIN for all of that USERS information, THEN with that information, querying LDAP again to see if the accounts unlocked, THEN querying LDAP again to see if the account is DISABLED.
So my question is... how exactly would I clean this up? I am new to using C# with AD and trying to make it work. Well it does work fine when on the internal network, its slow outside. I know it can be coded better and I'm not asking anyone to do it, just point me (or shove me) in the right direction to what I should change LOL.
Thanks in advanced!
|
|
|
|
|
Jacob Dixon wrote: how exactly would I clean this up?
what is that you want to clean up?
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
Well, the code works. I just think there would be an easier way / quicker way to get the information. Basically I am getting if the account is locked out, disabled, and the name and department. How I am doing this involves calling DirectoryEntry multiple times. When going through each name I'm wondering if I can get this information from the same DirectoryEntry all at the same time.
|
|
|
|
|
Ok I have modified it to do it all in one method... but its pulling computer objects too????
void AddListItemTest()
{
using (DirectoryEntry root = new DirectoryEntry())
{
root.Path = "LDAP://" + Properties.Settings.Default.LDAP;
root.Username = "****";
root.Password = "*****";
using (DirectorySearcher searcher = new DirectorySearcher())
{
searcher.SearchRoot = root;
searcher.SearchScope = SearchScope.Subtree;
searcher.Filter = "(&(objectClass=user))";
searcher.PropertiesToLoad.Add("department");
searcher.PropertiesToLoad.Add("name");
searcher.PropertiesToLoad.Add("userAccountControl");
searcher.PropertiesToLoad.Add("lockoutTime");
SearchResultCollection results = searcher.FindAll();
if (results != null)
{
foreach (SearchResult result in results)
{
ResultPropertyCollection props = result.Properties;
string Branch = "Unknown";
string Name = "";
int val = 0;
long ticks = 0;
foreach (string propName in result.Properties.PropertyNames)
{
if (propName == "name") Name = props[propName][0].ToString();
else if (propName == "department") Branch = props[propName][0].ToString();
else if (propName == "useraccountcontrol") val = (int)props[propName][0];
else if (propName == "lockouttime") ticks = (long)props[propName][0];
}
ListViewItem listItem = new ListViewItem(Name);
bool Locked;
if (ticks > 0) Locked = true;
else Locked = false;
if (val != (val & ~0x2)) listItem.ImageIndex = 2;
else if (Locked) listItem.ImageIndex = 1;
else listItem.ImageIndex = 0;
bool found = false;
foreach (ListViewGroup g in listViewUsers.Groups)
{
if (g.Header == Branch)
{
found = true;
listItem.Group = g;
break;
}
}
if (!found)
{
ListViewGroup g = new ListViewGroup(Branch, Branch);
listViewUsers.Groups.Add(g);
listItem.Group = g;
}
listViewUsers.Items.Add(listItem);
}
}
}
}
}
|
|
|
|
|
Ok what I did was change the filter to:
(&(objectcategory=person)(objectclass=user))
from
(&(objectClass=user))
Why would coputer objects show in the user class?
|
|
|
|
|