|
Hi,
What about using LINQ to read the specific line, writing is another story. I agree with Guffa about the writing each line again.
take the following into consideration: read all customers who live in UK.
var query =
from c in
(from line in File.ReadAllLines(filePath)
let customerRecord = line.Split(‘,’)
select new Customer()
{
Firstname = customerRecord[0],
Lastname = customerRecord[1],
JobTitle = customerRecord[2],
City = customerRecord[3],
Country = customerRecord[4]
})
where c.Country == "UK"
select c;
Regards,
The only programmers that are better those C# programmers are those who code in 1's and 0's |
Programm3r
My Blog: ^_^
|
|
|
|
|
Programm3r wrote: What about using LINQ to read the specific line
With the drawback that it always reads the entire file, even if you want a line at the beginning of the file.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guffa wrote: With the drawback that it always reads the entire file
This is true, on the other hand you can read it, once and perform various LINQ queries on it.
The only programmers that are better those C# programmers are those who code in 1's and 0's |
Programm3r
My Blog: ^_^
|
|
|
|
|
What does the text book say?
|
|
|
|
|
In my C# Application program, I have two DataGridViews which are not bound to any data source. I have coded them so that the user is allowed to drag and drop data between the two DGVs as well as within them.
So, when a data item in a cell is dragged and dropped on another cell, the data on the original is deleted - that is set to null.
The problem is, when I do that, after dropping, it automatically select the last cell (the one in which I just set the value to null).
How do I get that cell to be NOT selected?
Here is my code:
dgvSchedule.DoDragDrop(text, DragDropEffects.Copy);
if (bDataDrop == true)
{
dgvSchedule.Rows[info.RowIndex].Cells[info.ColumnIndex].Value = null;
dgvSchedule.Rows[info.RowIndex].Cells[info.ColumnIndex].Selected = false;
bDataDrop = false;
}
There, right after I set the value to null, I set the 'selected' property to false, but despite that it still selects that.
Please HELP!
|
|
|
|
|
try calling the refresh method of datagridview after you are done.
Ahsan Ullah
Senior Software Engineer
|
|
|
|
|
Nope mate, it doesn't work.
|
|
|
|
|
How do I enable freehand drawing on WPF or WPF browser application?
|
|
|
|
|
control.EnableFreehandDrawing = true;
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
Well, I'd start off with an InkCanvas if I were you - also, I'd look at posting this in the WPF forum, rather than the C# forum.
|
|
|
|
|
Hai friends,
I want to automate MSProject applicaton. Using early binding it is possible to me. But applying late binding i can't. Pls help me to automate mpp using latebinding...
When try to automate it gives an error : Exception from HRESULT: 0x80020006 (DISP_E_UNKNOWNNAME
Thanks in advance,
Praji
|
|
|
|
|
Hi,
I using visual studio 2003 with c# script and microsoft office excel 2003. I had add refrence microsoft office excel 11.0 object library. But when i start to run that show the error:
Excel.Application excelapp = new Excel.Applicationclass();
Can give me some idea?
|
|
|
|
|
Can you post here exception message ?
Parwej Ahamad
g.parwez@gmail.com
|
|
|
|
|
/*using Excel;
public Excel.Application excel_app;
string pathfile = @"C:\Inetpub\wwwroot\data\test.xls";
excel_app = new ApplicationClass();
Excel.Workbook excel_book = excel_app.Workbooks.Open(pathfile,0,true,5,"","",true,Excel.XlPlatform.xlWindows,"\t",false,false,0,true,1,0);
Excel.Worksheet excel_wsheet = (Excel.Worksheet)excel_book.ActiveSheet;
string firstName = ((Excel.Range)excel_wsheet.Cells[1,1]).Value2.ToString();
string lastName = ((Excel.Range)excel_wsheet.Cells[1,2]).Value2.ToString();
.....
.....
....*/
|
|
|
|
|
i am rather new to C#, i am switching from java, i followed through with a baisic c# screensaver tutorial, then i tried to add a picture and make it bounce around the screen. i added a picture box set to a picture(LM), i made a loop to make it move, then tried to figure out how to start it, i added it the end of load. this is probably extremely noobish and i am sorry,but if someone would help thatd be great
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace ScreenSaver
{
public partial class Form1 : Form
{
private int screenNumber;
private Point MouseXY;
int curX = 1;
int curY = 1;
Boolean running = true;
public Form1(int screen)
{
screenNumber = screen;
InitializeComponent();
this.run();
}
private void form1_Load(object sender, System.EventArgs e)
{
this.Bounds = Screen.AllScreens[screenNumber].Bounds;
Cursor.Hide();
TopMost = true;
}
private void onMouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (!MouseXY.IsEmpty)
{
if(MouseXY != new Point(e.X,e.Y))
{
running = false;
}
if(e.Clicks >0)
{
running = false;
}
}
MouseXY = new Point(e.X, e.Y);
}
public void run()
{
while (running)
{
loopMove();
Thread.Sleep(1000);
}
Close();
}
private void LM_Click(object sender, EventArgs e)
{
}
private void changeLMY(int y)
{
LM.Left += y;
}
private void changeLMX(int x)
{
LM.Top += x;
}
private void loopMove()
{
int fX = this.Top;
int fY = this.Left;
if (LM.Top >= fX - 300)
curX = -1;
if (LM.Top == 0)
curX = 1;
if (LM.Left >= fY - 300)
curY = -1;
if (LM.Left == 0)
curY = 1;
changeLMX(curX);
changeLMY(curY);
}
}
}
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace ScreenSaver
{
static class Program
{
[STAThread]
static void Main(String[] args)
{
if (args.Length > 0)
{
if (args[0].ToLower().Trim().Substring(0, 2) == "/c")
{
}
else if(args[0].ToLower()== "/s")
{
}
else if (args[0].ToLower() == "/p")
{
}
}
else
{
for (int i = Screen.AllScreens.GetLowerBound(0); i <= Screen.AllScreens.GetLowerBound(0); i++)
{
System.Windows.Forms.Application.Run(new Form1(i));
}
}
}
|
|
|
|
|
|
Why not use the Project|Properties|Resources and just drag and drop onto there? Then you can just use Properties.Resources.yourimagewithoutextension
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
hy everyone!
we do have a problem:
we coded a webpart which allows searching and printing of document in a document store. you search for files, you are able to display them and you are able to print them.
therefor we wrote a printservice, which fetches the file from the store and sends them to the spooler and printer respectively. that works fine. afterwords we update the database to set some fields, indicating the file was already printed.
when using a little amount of files it works file, but the bigger the collection of file is, the more problems appear. meaning, when selecting around 100 files with around 1 MB each, a thread abort exception is thrown. if there are just 40 files, no exception is thrown.
and to complicate the situation: if you repeat printing the same files lets say for 10 times, it works in lets say 7 tries and fails in 3 tries. sometimes it even works in all tries or it fails more often. its like guessing numbers in a lottery.
but it does not throw the thrad abort exception during printing, it throws the exception when returning to the code of the webpart where the printing was invoked at. meaning we wrote a printbuttonclick event-function which invokes the printservice with the file ids, and some other properties. and when returning the exception is thrown.
we tried to change the timeout of the printservice indefinite (-1), we also tried to change the code to get as much performance as possible, we also did a lot of garbage collection etc. but we can't get rid of this exception.
we also have already been googling for this incident, but nothing really solved our problem. we were just able to send more files until it is likely to be thrown.
printing around 100 files could take up to 1-2 minutes, so i guess maybe this could take to long and the thread times out when returning.
does anyone have an idea of
1) where to start to get an idea how to get rid of this error (maybe a page of hints we haven't already been to etc.)
2) how to get rid of this exception. maybe one of you has already encountered anything similar.
thanks for any hints and ideas.
if you do need some further infos for understanding or to get an idea of how to solve it, just feel free to ask.
thanks!
stephan.
|
|
|
|
|
The only thing that the ThreadAbortException is used for, is aborting threads. That is done by calling the Abort method of a Thread, which then throws the exception in the thread in order to abort it.
So, are you aborting any thread?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
nope, i am not aborting any thread.
i forgot to add an important info: sharepoint is located on two servers, meaning there is a loadbalancing installed using two servers. could it be, the task is switched to the other server when returning?
meaning when starting the printing from server A to sharepoint it looks like as if the server is very busy and when returning it is switched to server B, but there is not thread active so it thinks it is aborted?
that's an idea which I had when talking to some other guys.
|
|
|
|
|
For example, lets say I have 500 proxies and I wanted to check them all. How could I split those up into a random amount of threads(User inputted) and check them all at once using multiple threads.
Thanks,
BuckleyInDaHouse.
|
|
|
|
|
You probably can't check them all at once, because you might overload the computer and/or the network.
Start a couple of worker threads, and let them check the proxies one at a time.
If you search for SynchronisedQueue, you will find a class that I wrote a while back. You can use it to let the threads get one task at a time from a common queue, and to let all the threads return the results to the main thread.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi
I have written the following asp.net page and creating the xml file through a method everything is fine it is creating the file but i have a problem. May be you can help for that. it is about the xml file output when it created it showing TABLE and TABLE1 as node in xml how i can change it to meaningful name. My Code is as follows. XML file is at the bottom of the code
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Xml;
using System.IO;
public partial class _Default : System.Web.UI.Page
{protected void Page_Load(object sender, EventArgs e){
GetEmployees("London");
}
public static void GetEmployees(string City){
//String sConnection = "server=HTCWEBDEMO;database=hometrust;user id=ht_admin;password=htc_tr!st";
String sConnection = "server=ZAFAR-PC\\SQLEXPRESS;Integrated Security=SSPI;database=northwind";
SqlConnection mySqlConnection = new SqlConnection(sConnection);
mySqlConnection.Open();
// Get the same data through the provider.
//string mySQLStatement = "SELECT Title,FirstName,LastName,PhoneNumber,Faxnumber, email from contactlist where TeamName='" + TeamName +"'; select FirstName, LastName from contactlist where TeamMorty ='True' and teamname='" + TeamName + "';";
string mySQLStatement = "SELECT FirstName,LastName,Title,City from employees where city= '" + City + "';select FirstName, LastName from employees where city='" + City + "';";
//SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter(mySQLStatement, sConnection);
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter(mySQLStatement, sConnection);
DataSet myDataSet2 = new DataSet();
myDataSet2.DataSetName = "Contacts";
mySqlDataAdapter.Fill(myDataSet2);
// Write data to files: data1.xml and data2.xml for comparison.
myDataSet2.WriteXml("c:/temp/ContactList.xml");
mySqlConnection.Close();
}
}
XML FILE OUTPUT
<?xml version="1.0" standalone="yes" ?>
- <Contacts>
- <Table>
<FirstName>Steven</FirstName>
<LastName>Buchanan</LastName>
<Title>Sales Manager</Title>
<City>London</City>
</Table>
- <Table>
<FirstName>Michael</FirstName>
<LastName>Suyama</LastName>
<Title>Sales Representative</Title>
<City>London</City>
</Table>
- <Table>
<FirstName>Robert</FirstName>
<LastName>King</LastName>
<Title>Sales Representative</Title>
<City>London</City>
</Table>
- <Table>
<FirstName>Anne</FirstName>
<LastName>Dodsworth</LastName>
<Title>Sales Representative</Title>
<City>London</City>
</Table>
- <Table1>
<FirstName>Steven</FirstName>
<LastName>Buchanan</LastName>
</Table1>
- <Table1>
<FirstName>Michael</FirstName>
<LastName>Suyama</LastName>
</Table1>
- <Table1>
<FirstName>Robert</FirstName>
<LastName>King</LastName>
</Table1>
- <Table1>
<FirstName>Anne</FirstName>
<LastName>Dodsworth</LastName>
</Table1>
</Contacts>
|
|
|
|
|
|
Nice reply in the other forum
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|