|
thank you for your answer, if you can give me a quick example to analyze the file, and thank you, please I really need it
|
|
|
|
|
You will need to write your own logic for this (once you decide on the structure of your text file).
|
|
|
|
|
membre123 wrote: how to fill a standard list dictionary <> from a text file????
Here's a little sample - it has no error handling or anything nice about it.
using System;
using System.Collections.Generic;
using System.IO;
namespace ConsoleApplication1
{
class Customer
{
public int ID;
public string name;
}
class Program
{
static void Main(string[] args)
{
var Customers = new Dictionary<int, Customer>();
using (StreamReader fs = new StreamReader(@"C:\Stuff\theInputFile.txt"))
{
string dataLine;
while ((dataLine = fs.ReadLine()) != null)
{
string[] s = dataLine.Split(',');
int id = int.Parse(s[0]);
Customer c = new Customer();
c.ID = id;
c.name = s[1].Trim();
Customers.Add(c.ID, c);
}
}
foreach (var item in Customers)
{
Console.WriteLine("ID: {0} Customer {1}", item.Key, item.Value.name );
}
Console.ReadLine();
}
}
}
What you have to do depends entirely on the declaration for Customer and the layout of the input file.
My input file looks like this:
1, Jet Black
2, Hugh Cornwell
3, Joe Strummer
4, Sid Vicious
membre123 wrote: and what is the other command to read and write in a small file size to share filestream????
I don't know what this means.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
think you very mutch, that what's i need
|
|
|
|
|
Hi all,
Can anybody provide me the regex to replace the '&' with '&' but the '&' character in word like '&','<' '>' etc shoud be ignored.
Frankly speaking I am weak in regular expression.
I would be highly thankful if somebody provide me the good learning articles on this.
Thanks
Rohit
|
|
|
|
|
It's not too complex, if you do it via a MatchEvaluator, as you will probably have to examine each case of '&' in context:
Regex regexWithAllPossible = new Regex(@"(>|<|&|&)");
string result = regexWithAllPossible.Replace(source, new MatchEvaluator(CheckMatch));
...
private string CheckMatch(Match m)
{
if (m.Value == "&")
{
return "&";
}
return m.Value;
} Remember to list all the possibilities in the regex!
Get a copy of Expresso[^] - it decodes, creates, and tests regexs! It's free and really helps.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Thanks dear, you really did a great job for me.
I will definately look into expresso.
|
|
|
|
|
You are welcome!
Expresso is a good piece of kit - I've been using it for about a year and really wish I'd written it.
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
Hello friends
I have a messaging system that uses p2p. Each peer has a incoming message list and a outgoing message list.
What I need to do is whenever a new peer will join the mesh he will get the all the incoming messages from other peers and add those into it's own incoming message list. Now I know when I get the other peer info from I can ask them to give their own list to me. But I'm not finding the way how..?
Any suggestion on this or help would be highly appreciated. I'm giving my code below.
Thanking in Advance
Johnny
#region Instance Fields
private string strOrigin = "";
private string m_Member;
private IServerChannel m_participant;
private InstanceContext m_site;
private NetPeerTcpBinding m_binding;
private ChannelFactory<IServerChannel> m_channelFactory;
private IOnlineStatus o_statusHandler;
private delegate void NoArgDelegate();
private IUserService userService;
ObservableCollection<AppLoginInstance> appLoginInstances;
ObservableCollection<MessageType> inComingMessageTypes;
ObservableCollection<PDCL.ERP.DataModels.Message> outGoingMessages;
ObservableCollection<PDCL.ERP.DataModels.Message> inComingMessages;
private readonly IEventAggregator eventAggregator;
private IUnityContainer container;
private RefreshConnectionStatus refreshConnectionStatus;
private RefreshConnectionStatusEventArgs args;
private ReplyRequestMessage replyMessageRequest;
private ReplyRequestMessageEventArgs eventsArgs;
#endregion
public P2pMessageService(IUserService UserService, IEventAggregator EventAggregator, IUnityContainer container)
{
userService = UserService;
this.container = container;
appLoginInstances = new ObservableCollection<AppLoginInstance>();
inComingMessageTypes = new ObservableCollection<MessageType>();
inComingMessages = new ObservableCollection<PDCL.ERP.DataModels.Message>();
outGoingMessages = new ObservableCollection<PDCL.ERP.DataModels.Message>();
this.args = new RefreshConnectionStatusEventArgs();
this.eventsArgs = new ReplyRequestMessageEventArgs();
this.eventAggregator = EventAggregator;
this.refreshConnectionStatus = this.eventAggregator.GetEvent<RefreshConnectionStatus>();
this.replyMessageRequest = this.eventAggregator.GetEvent<ReplyRequestMessage>();
}
#region IOnlineStatus Event Handlers
void ostat_Offline(object sender, EventArgs e)
{
}
void ostat_Online(object sender, EventArgs e)
{
try
{
m_participant.Join(userService.AppInstance);
}
catch (Exception Ex)
{
Logger.Exception(Ex, Ex.TargetSite.Name + ": " + Ex.TargetSite + ": " + Ex.Message);
}
}
#endregion
#region IServer Members
public void ConnectToMesh()
{
try
{
m_site = new InstanceContext(this);
m_binding = new NetPeerTcpBinding("P2PMessageBinding");
m_channelFactory = new DuplexChannelFactory<IServerChannel>(m_site, "P2PMessageEndPoint");
m_participant = m_channelFactory.CreateChannel();
o_statusHandler = m_participant.GetProperty<IOnlineStatus>();
o_statusHandler.Online += new EventHandler(ostat_Online);
o_statusHandler.Offline += new EventHandler(ostat_Offline);
BackgroundWorkerHelper.DoWork<object>(() =>
{
m_participant.InitializeMesh();
return new object();
}, arg =>
{
});
this.appLoginInstances.Add(this.userService.AppInstance);
}
catch (Exception Ex)
{
Logger.Exception(Ex, Ex.TargetSite.Name + ": " + Ex.TargetSite + ": " + Ex.Message);
}
}
public void Join(AppLoginInstance obj)
{
try
{
if (appLoginInstances.SingleOrDefault(a => a.InstanceId == obj.InstanceId)==null)
{
appLoginInstances.Add(obj);
this.refreshConnectionStatus.Publish(new RefreshConnectionStatusEventArgs() { Status = m_channelFactory.State });
}
m_participant.SynchronizeMemberList(userService.AppInstance);
}
catch(Exception Ex)
{
Logger.Exception(Ex,Ex.TargetSite.Name + ": " + Ex.TargetSite + ": " + Ex.Message);
}
}
public void SynchronizeMemberList(AppLoginInstance obj)
{
try
{
if (appLoginInstances.SingleOrDefault(a => a.InstanceId == obj.InstanceId) == null)
{
appLoginInstances.Add(obj);
}
}
catch (Exception Ex)
{
Logger.Exception(Ex, Ex.TargetSite.Name + ": " + Ex.TargetSite + ": " + Ex.Message);
}
}
public void BroadCastMsg(PDCL.ERP.DataModels.Message msg, List<string> securityLevels)
{
try
{
foreach (string s in securityLevels)
{
if (this.userService.IsInRole(s))
{
if (this.inComingMessages.Count == 0 && msg.CreatedByApp != this.userService.AppInstanceId)
{
this.inComingMessages.Add(msg);
}
else if (this.inComingMessages.SingleOrDefault(a => a.MessageId == msg.MessageId) == null && msg.CreatedByApp != this.userService.AppInstanceId)
{
this.inComingMessages.Add(msg);
}
}
}
}
catch (Exception Ex)
{
Logger.Exception(Ex, Ex.TargetSite.Name + ": " + Ex.TargetSite + ": " + Ex.Message);
}
}
public void BroadCastReplyMsg(PDCL.ERP.DataModels.Message msg)
{
try
{
this.replyMessageRequest.Publish(new ReplyRequestMessageEventArgs() { Message = msg });
this.inComingMessages.Remove(this.inComingMessages.SingleOrDefault(o => o.MessageId == msg.MessageId));
}
catch (Exception ex)
{
Logger.Exception(ex, ex.TargetSite.Name + ": " + ex.TargetSite + ": " + ex.Message);
}
}
public void Whisper(string Member, string MemberTo, string Message)
{
}
public void InitializeMesh()
{
}
public void Leave(AppLoginInstance obj)
{
if (this.appLoginInstances.SingleOrDefault(a => a.InstanceId == obj.InstanceId) != null)
{
this.appLoginInstances.Remove(this.appLoginInstances.Single(a => a.InstanceId == obj.InstanceId));
}
}
#endregion
|
|
|
|
|
Hi!
I have a question.
I have two ListBoxes with an Add and Remove Button. Currently I list all my options in ListBox1 using the following code:
ListBox1.DataSource = payItemClass.GetPayItems();
ListBox1.DisplayMember = "PayItem.Code";
ListBox1.ValueMember = "PayItem.Id";
How can I move the items I select in ListBox1 to ListBox2 and then save them to my sql table?
Thank you in Advance!!
Illegal Operation
|
|
|
|
|
ListBox has a property named SelectedItems. Use it to get the selected itmes in listbox1
and add them to listbox2. As for adding them to SQL either use stored procs or querys but try to
use parameters.
Something like this silly example to copy the items from one lst to another:
listBox2.BeginUpdate();
listBox2.Items.Clear();
foreach (var item in listBox1.SelectedItems)
{
listBox2.Items.Add(item);
}
listBox2.EndUpdate();
pseudo only kind of(for SQL table):
SQLConnection con = new SqlCommand(ConnStringHere);
SQLCommand cmd = new SqlCommand();
cmd.Conection = con;
cmd.CommandText = "Inserto Into TblName(ColName1, ColName2) Values(@paramName1, @paramName2)"
cmd.Parameters.AddWithValue("@paramName", paramValue);
.
.
.
Just an irritated, ranting son of ... an IT guy.
At your trolling services
modified on Wednesday, May 5, 2010 2:50 AM
|
|
|
|
|
If you have not yet solved your problem, try looking at this thread[^]. The problem sounds basically the same as yours.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
HI,
in my code, I am checking for a excel file exists or not. if it doesn't exists i am trying to creating new one along with some columns. here i am able to create the excel file but i don't know how to add columns to it. can any one please help??
below is my code block.
private void CheckExcelfile()
{
string path = @"C:\Servicedeatils.xls";
if (!File.Exists(path))
{
using (StreamWriter sw = File.CreateText(path))
{
How to add columns to the created excel file??
}
}
}
fttyhtrhyfytrytrysetyetytesystryrty
|
|
|
|
|
This is very wrong.
You are not creating a Excel file, but a text file with the extension .xls.
To use Excel you mainly have 2 options:
1) Interrop
2) OleDB
* 3) Commercial apps that ease process of writing/reading to/from Excel.
Bingle for "Excel C#" and you'll find many resources.
Here on CP there are some nice articles on using Excel.
Just an irritated, ranting son of ... an IT guy.
At your trolling services
|
|
|
|
|
Hi,
Thanks for reply.
instead of using File.CreateText, i can use File.Create(path) also i think this will create the required file. but here i am struck with adding columns to it. how to do that?
fttyhtrhyfytrytrysetyetytesystryrty
|
|
|
|
|
You should read the reply from MDL=>Moshu more carefully.
There is no such thing as File.CreateExcel(path) in C#.
Real xls files are created by Excel or some library that knows about xls files.
Cheers
I don't like my signature at all
|
|
|
|
|
Hi,
How to display RTF file in crystal report? and also is it possible to display any no. of pages in crystal report and is it possible to create RTF file without having microsoft word installation?
Regards
Kanna.
|
|
|
|
|
Dotnetkanna wrote: How to display RTF file in crystal report?
Using a memo-field. Be sure to set the "field format" to RTF, and make sure that the RTF is valid.
Dotnetkanna wrote: also is it possible to display any no. of pages in crystal report
That's possible.
Dotnetkanna wrote: is it possible to create RTF file without having microsoft word installation?
Yup, for example by using the "WordPad" application that comes with Windows, or by installing OpenOffice.
I are Troll
|
|
|
|
|
Hi eddy,
Thx man.if the rtf file content is more than one page then the content is not displaying in the next page. i have adding these content through OLEObject. any idea?
Regards
Kanna.
|
|
|
|
|
I'd go for a text[^]-field with the formatting set to RTF, and not an OLE-field.
Open the format editor, go to the paragraph tab, choose "format field" and select the correct text interpretation.
I are Troll
|
|
|
|
|
Yes.im using rtf formmat only.but the rtf content display only in one page remaining text is not appearing in the next page.what i have to do?
regards
kanna
|
|
|
|
|
Dotnetkanna wrote: but the rtf content display only in one page remaining text is not appearing in the next page.what i have to do?
According to my reference[^], you'd only have to specify that it can grow.
I are Troll
|
|
|
|
|
Hi Experts,
I was really excited when I learned the usage of INotifyPropertyChanged interface. It made binding a bliss and the UI highly interactive and dynamic for me. But then with every problem comes a solution and more problems.
I will explain my question with an example. I have a student class.
public class Student : INotifyPropertyChanged
{
const int MINIMUM_AGE = 1;
int rollNumber = 0;
int age = 0;
string studentName = string.Empty;
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
#endregion
public Student() { }
public Student(string studentName, int age, int rollNumber)
{
this.StudentName = studentName;
this.StudentAge = age;
this.RollNumber = rollNumber;
}
public string Name
{
get
{
return this.studentName;
}
set
{
if (value != this.studentName)
{
if (value.Trim() == string.Empty)
throw new Exception("Name assigned does not confirms to the format. Please assign a proper alphanumeric value.");
this.studentName = value;
this.DisplayPropertyChange("StudentName");
}
}
}
public int StudentAge
{
get
{
return this.age;
}
set
{
if (value != this.age)
{
if (value < MINIMUM_AGE)
this.age = MINIMUM_AGE;
else
this.age = value;
this.DisplayPropertyChange("StudentAge");
}
}
}
public int RollNumber
{
get
{
return this.rollNumber;
}
set
{
if (value != this.rollNumber)
{
if (value < 0)
throw new Exception("Wrong value supplied. Only non negative integers allowed.");
this.rollNumber = value;
this.DisplayPropertyChange("RollNumber");
}
}
}
void DisplayPropertyChange(string propertyName)
{
if (null!=this.PropertyChanged)
{
this.PropertyChanged(this,new PropertyChangedEventArgs(propertyName));
}
}
}
So far so good. Binding to any of the property would reflect the change in the bound object.
Now, in the same class a property type is a complex/user defined type. Then how are we going to handle it.?e.g.
say in the above class the Name property is changed to the following class instead of string:
public class StudentName
{
string firstName = string.Empty;
string lastName = string.Empty;
public string FirstName
{
get { return firstName; }
set { firstName = value; }
}
public string LastName
{
get { return lastName; }
set { lastName = value; }
}
public string FullName
{
get { return String.Concat(this.firstName," ",this.lastName); }
}
public StudentName()
{}
public StudentName(string firstName, string lastName)
{
this.firstName = firstName;
this.lastName = lastName;
}
}
And I would access it with something like:
Student student=new Student();
string.Format("The student's name is {0}",student.Name.FullName);
I implemented the INotifyPropertyChanged interface in the class StudentName too. But the change is still not getting reflected automatically.
IF INotifyPorpertyChanged is not extendable for complex property is there some workaround?
Or am I overlooking some Object Oriented Concept here?
Any help will be highly appreciated.
Best Regards,
Sid
|
|
|
|
|
the simplest way will be to not implement the INotifyProperty... in the SutdentName class.
For this to work you need to implement the IEquatable<> interface
or overrdide the equals method so that the StudentClass will know how to check for equality the
StudentName objects.
In the Student Class a add a Property for the student name of type StudentName and offcourse a private field to back it up.
ex:
public StudentName Name
{
get
{
return this.studentName;
}
set
{
if (value != this.studentName)
{
if (value.Trim() == string.Empty)
throw new Exception("Name assigned does not confirms to the format. Please assign a proper alphanumeric value.");
this.studentName = value;
this.DisplayPropertyChange("Name");
}
}
}
Just an irritated, ranting son of ... an IT guy.
At your trolling services
modified on Wednesday, May 5, 2010 2:08 AM
|
|
|
|
|
Try this (pay special attention to the lines that are bolded and underlined):
public class StudentName : INotifyPropertyChanged
{
string firstName = string.Empty;
string lastName = string.Empty;
public string FirstName
{
get
{
return firstName;
}
set
{
if (firstName != value)
{
firstName = value;
this.OnPropertyChanged("FirstName");
this.OnPropertyChanged("FullName");
}
}
}
public string LastName
{
get
{
return lastName;
}
set
{
if (lastName != value)
{
lastName = value;
this.OnPropertyChanged("LastName");
this.OnPropertyChanged("FullName");
}
}
}
public string FullName
{
get
{
return String.Concat(this.firstName, " ", this.lastName);
}
}
public StudentName()
{
}
public StudentName(string firstName, string lastName)
{
this.firstName = firstName;
this.lastName = lastName;
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string name)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
}
|
|
|
|