« first day (1276 days earlier)      last day (3687 days later) » 

5:55 AM
hi all
can i ask how can i copy specific file from 1 folder to another using c#?
e.g: in folder there are diff. filetypes (e.g: .cs, .js, .exe) but only .cs i wanted to copy from 1 folder to another then i want to rename it
 
Ken
6:07 AM
@Elegiac still relevant?
 
i dunno if its ok to use .EndsWith("") on path but seems like it worked
 
Ken
Looks odd tbh, if you'd show exactly what's going on I could try and see what's causing you to do this
Unless this isn't important (e.g. not production code)
Always here to help ofc ^^
 
@Ken what should i do to obtain that w/o using .endswith
 
Ken
Could you show me the line/statement that you used it in?
 
sure
            string sourcePath = @"c:\deletethis";
            string targetPath = @"C:\deletethis\deletethis2";
            if (!Directory.Exists(targetPath))
            {
                Directory.CreateDirectory(targetPath);
            }
            foreach (var srcPath in Directory.GetFiles(sourcePath))
            {
                //Copy the file from sourcepath and place into mentioned target path,
                //Overwrite the file if same file is exist in target path

                if (srcPath.EndsWith(".cs"))
it seems worked but i guess .endswith was not a properway to do it?
 
Ken
6:16 AM
Well, .EndsWith("") is not, but the question is if you want only .cs files to be copied.
 
yes
 
Ken
Because I see that it's not .EndsWith(""), but .EndsWith(".cs")
Then it is perfect ^^ also consider making your string variables constants.
I'd also suggest removing the braces for the one-statement blocks, but it is just a matter of personal choice.
 
thanks :) but what should i do to rename all file
i want to add date in every file that been copied
e.g: from test.cs to test41414.cs
 
Ken
If you would want to preserve the extension (".cs") you'll have to include a bit of additional logic. Let me write that for you real quick with comments so you could use and learn along the way, hold on.
Allow me to rename the identifiers to clearer ones?
 
yes sure
ty :)
var dateNow = DateTime.Now.ToString("MMddyyyy");

or with something like
on endname
before .cs
 
Ken
6:23 AM
Coming up ^^
There:
const String sourceDirectoryPath = @"C:\deletethis";
const String targetDirectoryPath = @"C:\deletethis\deletethis2";

if (!Directory.Exists(targetDirectoryPath))
Directory.CreateDirectory(targetDirectoryPath);

foreach (var sourceFilePath in Directory.GetFiles(sourceDirectoryPath))
{
//Copy the file from sourcepath and place into mentioned target path,
//Overwrite the file if same file is exist in target path

// Get the same path but in the target folder
var destinationPath = sourceFilePath.Replace(sourceDirectoryPath, targetDirectoryPath);
Keep in mind this is not tested, but either way it will give you the idea on how to accomplish it.
 
ill try it
i got an error access to the path is denied maybe theres something wrong with my path
 
Ken
Are you using Visual Studio / Visual C#?
 
yes
im trying to figure out why i got this error
 
Ken
When the exception is caught in the debugger, hover your mouse on the "destinationPathWithDate" variable and please copy the value of it here
You should see it pop out.
Or if you'd like I can rewrite the entire thing in a more modular way so I could also test it, and it would be considered better quality code.
 
6:40 AM
deletethis204142014.cs
 
Ken
Oh then it seems it's missing the parent directory, you could fix it simply by adding "targetDirectoryPath + " behind it.
Is this production code btw?
 
yes it is
 
Ken
Oh, then no offense but it is very hacky. I'll re-write this functionality for you in a proper OOP manner and it should bring you a lot of joy to work with.
 
thanks @Ken
btw ill try to change the path im still in testing progress atm
 
Ken
Just have a disclaimer that my code is extra-modular and quite abstract so you might wanna hide it in a file, but I can assure you it is very pleasant to work with ^^.
It is my pleasure
 
6:45 AM
and im applying codes in actualproject
now
after this
 var sourceFilePathWithoutExt = Path.GetFileNameWithoutExtension(destinationPath);
 
Ken
Alright, I will ding your name when I am ready, should take me between a minute to 3 I assume
 
it gets the target folder
 
Ken
The actual code I sent you earlier would be useless for you for production
 
ill try to debug also thanks
 
Ken
It is not something maintainable or pleasant
My pleasure ^^
 
6:49 AM
oh i'm sicker than a dog, it must be the f'n plague or something
 
Ken
Aww, is it a cold / flu, or something serious?
 
no idea, i feel like death
 
Ken
If I may suggest get some vitamin C for your immune system, keep warm and see a doctor of course. Hope it will go away soon.
 
and that sucks because i hate missing work
 
Just don't die on us. Im not sure how to remove a zombie from the chat room.
 
6:53 AM
;)
just lure me away with chicken
 
I recomend
if the first one doesn't help double the rum in the second one.
 
Ken
@Elegiac It seems to take me a bit longer XD but don't worry, still working on it.
 
mmmm
 
np im eating lunch atm .xD
while debugging
 
Ken
Oh enjoy ^^
I know this is a wrong thing to say in a C# room but.. god, I'm so annoyed to work with it XD
 
7:03 AM
lol sry about that bro ...
 
Ken
Oh nu don't be, it's my pleasure to help ^^
Really
 
WHY AM I DYING
 
Ken
SEE A DOCTOR!
 
paging dr. House
hey roel
 
Ken
@Elegiac It is done, but would you like me to add documentation?
(There is none whatsoever)
 
7:13 AM
its ok if theres no docu @Ken
 
Ken
Alright, if you'll need it let me know and I'll add right away.
Usage sample:
        IPathTransformer transformer = new PathTransformer(new MovePathTransformer(@"C:\Target"), new TodayDatePathTransformer());
        var result = transformer.Transform(@"C:\Source\file.txt");
        Console.WriteLine(result);
(looks very readable with syntax highlighting XD not like it is here)
 
wow cool
but wheres the .Copy in there ..
 
Ken
Oh there isn't but getting that copy is very easy. Hold on I'll write you a snippet and you'll see how easy this makes it.
Know what, I'll write the entire thing to save ya some time. Hold on.
The entire thing becomes this:
        IPathTransformer transformer = new PathTransformer(new MovePathTransformer(@"C:\Target"), new TodayDatePathTransformer());
        foreach (var sourceFile in Directory.EnumerateFiles(@"C:\Source").Where(path => path.EndsWith(".cs")))
            File.Copy(sourceFile, transformer.Transform(sourceFile), true);
Did not test, but should work.
 
ill try it :D
 
Ken
Alright, let me know how it goes ^^
 
7:28 AM
cool it worked! thanks man bro
 
you're welcome
 
Ken
My pleasure ^^ glad I could help
 
;)
 
ill try to read it
 
Ken
That'd be great, if any question arise let me know
Steve, you high XD
 
7:29 AM
String.Concat(name, _value, extension)
i think this is the properway to do it on path
 
Ken
Steve he is not talking about when you want to separate directories.
Concat is used there just to join them (much like the + operator).
 
Easier to use the + operator :)
 
Ken
It represents the name of the file without any directory
 
(in this case, not a path, I know)
 
Ken
7:33 AM
Indeed but String.Concat has different overloads for better results.
By better I mean faster, of course.
 
No?
a + b + c when all are strings compiles into a call to String.Concat(a, b, c)
 
Ken
Oh I didn't know, can you show me a source for that?
 
Let me see if the c# specification mentions it
You can try it out with LINQPad, just click on the IL tab below the code to see what the IL looks like after compiling.
 
Ken
Sure, thank you ^^
I'll disassemble right now and see.
(I don't use LINQPad)
 
The C# specification doesn't mention it, in the annotated version there is a comment by Jon Skeet that mentions it in passing, but nothing formal. I'll have to dig a bit to find any official mention of it, though there may be none.
 
Ken
7:38 AM
Ah that's okay then.
 
And you should fix the "(I don't use LINQPad)" error. ;)
 
Ken
Oh XD how come? I never got the deal with it tbh.
 
It's just so easy to test small code snippets like this
And the .Dump() extension method is just brilliant, dumping out data structures hierarchically
 
Ken
Oh, I'm hardly using C# anymore
Only when have to like for ASP.NET or WPF
 
hello sir
can 1 event have multiple event handlers?
 
7:51 AM
like?
 
good morning people
 
like
onclick event
 
Ken
Hey everyone ^^
 
i write 2 event handlers for onclick
which will be called one after other
 
why do you want something like that
event woint fire at once
one is first then second
what do you want to achieve
 
7:53 AM
ok
there are 2 buttons
 
You can hook more than one event handler to the same event, yes
 
i want same onclick handler for both of them
 
btn.Click += a;
btn.Click += b;
When you click the button, a and b will be fired.
you mean
btn1.Click += a;
btn2.Click += a;
?
 
yes
 
i will make these eventhandlers in plugins
 
7:54 AM
test it :)
 
That will work
 
hi
 
Ken
Hey Leon
 
it funny to have 2 buttons that do the same thing
 
hello ken :)
 
7:55 AM
Depends, in a calculator you probably have 10 buttons doing "the same thing"
 
Ken
Perhaps, @Shift, but pretty common
 
it can I don't no i never use it :)
 
I'm first in chatroom. Whats the rules here
 
the rule is
 
Ken
Just enjoy yourself ^^
 
7:55 AM
pay everybody 10 euro for entering :)
2.50 per question
 
=D @shift
 
hi guys im trying hard figure it out how to allow only numbers in textbox and if was typed a non digit, show it and remove it.
I want without regex
i tred this
 
Ken
WinForms or WPF?
 
char[] entereddata = nsTextBox2.Text.ToCharArray();
foreach (char aChar in entereddata.AsEnumerable())
{
if (!Char.IsDigit(aChar))
{
MessageBox.Show(aChar + " is not numeric.", "Attention", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
nsTextBox2.Text = nsTextBox2.Text.Replace(aChar, ' ');
}
}
winforms
pls help me..
 
What kind of data is entered in the textbox?
 
Ken
7:59 AM
'' as an empty character is not valid, as it is for empty string ("")
 
string
 
no, what kind of data
 
its fun here.... I can question expert live.... :)
 
information
 
port number
 
8:00 AM
phone number? ssn? currency?
ok, and what is the question then?
 
Ken
He wants validation
 
I understand that
but it seems he already has code to handle it, so what is the question?
 
so if im typing 2034F
it must say to mey "F" is not a digit
and remove it
 
does it?
 
but it doesn't remove it.
i couldn't figure it out...
 
8:01 AM
not allowing is better then removing
 
try .Replace(aChar.ToString(), "")
 
it doesn't work..it popping up the messagebox unlimited
i tried a lot.....
 
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar)
&& !char.IsDigit(e.KeyChar)
&& e.KeyChar != '.')
{
e.Handled = true;
}

// only allow one decimal point
if (e.KeyChar == '.'
&& (sender as TextBox).Text.IndexOf('.') > -1)
{
e.Handled = true;
}
}
 
yes this is working but
im in textbox1_textchanged
here i need to type
i just hope someone from here will help me..
 
have you tried debugging?
 
8:05 AM
tried..
 
dont use messagebox
its annoying
1000 messagebox will popup ofc if someone is pressing letters all the time
 
then how can i remove it
?
if letter was typed
 
removing the character is not the same as the messagebox
 
by allowing only numbers
then you dont need to remove it
 
8:07 AM
and how can i allow only numbers? in texbox_textchanged
 
place a breakpoint on the line doing the replace, step over it, and see if it actually removes the character
 
i've done it and it doesn't remove it
 
well then obviously you need to find out why
 
use Keypress insted of textchanged
 
because it should
try this
string temp = nsTextBox2.Text;
temp = temp.Replace(aChar.ToString(), "");
nsTextBox2.Text = temp;
then inspect the value of temp before assigning it back to the textbox.
you're triggering the textchanged event from inside the textchanged event, this may not be safe to do
 
8:10 AM
yes but i dont' want keypess because people can paste a non digit
not typing it
 
you can combine it also
if you want
I think if you paste a long string in your textchanged handler
it will indeed fire alot messageboxes
 
4 digit number and it pops up infinitelly
Lasse V. it doesn't remove it either..
 
Ok, then you have a bug in your code
 
but what bug?
 
I can't tell because I don't see your variable contents
You need to look at the string, look at aChar, see that it is correct, and verify that the string does indeed contain that character
 
8:13 AM
loop every char in your textbox
check if its a letter or number
 
Which character are you testing with?
 
if letter remove it from the found position
 
okey so when i tried yours again
 
I've got a question...: Is it possible to auto-run my software on startup of windows, without putting a shortcut in the Startup folder???
 
no messageboxes
 
8:13 AM
it show me
An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.dll
here:
public override string Text
{
get { return base.Text; }
set
{
base.Text = value;
if (Base != null)
{
Base.Text = value;
}
}
}
 
Base with uppercase B?
what is Base?
 
so this nsTextBox
it's a control created
 
comment out the if-statement and assignment to Base and see if that fixes the problem
 
oke i`ll try
 
but I doubt it, you've already verified that it's the Replace call that is not doing its job, since you said that temp did not change.
 
8:18 AM
yes it doesn't work..
 
Have you verified the contents of temp and aChar
is the character in aChar really in temp at all?
 
yes it is
 
and again, which character are you testing with?
 
so im typing like this: 2322d
 
how do i populate my listview with data from mysql database
 
8:20 AM
and when you stop at this line:
temp = temp.Replace(aChar.ToString(), "");
does temp contain "2322d"?
and aChar contains 'd'?
and stepping over it, temp still contains "2322d"?
 
char[] entereddata = nsTextBox2.Text.ToCharArray();
foreach (char aChar in entereddata.AsEnumerable())
{
if (Char.IsDigit(aChar))
{
string temp = nsTextBox2.Text;
temp = temp.Replace(aChar.ToString(), "");
nsTextBox2.Text = temp;
}
}
so is liek this
 
that's a direct copy paste from your code?
 
yes
and temp contains 2014d
and aChar 2
...
 
ok
does it remove the 2?
is the string "014d" afterwards?
 
I wish to make a question. I made a project on human resource management. I know a little about ms sql and entity framework. As I'm new in .NET world, what should be my next target to learn. I'm a student. could anyone give me some suggestion? please..
 
8:23 AM
Lasse one moment
i putted ! in if (!Char.IsDigit(aChar))
but it doesn't remove it
 
Look, there's no way I can help you if every turn I ask a question, you don't answer it, change your code, and keep complaining that it doesn't work
Can you put a breakpoint on the line doing a replace on temp and tell me what the string and character value contains
then step over it, and tell me what temp contains after calling replace
without changing the code in the meantime?
 
@LasseV.Karlsen @user3313264 use teamviewer
 
don't try to figure out if I want you to see something in the code
No
not going to use teamviewer
 
okey so temp 2014s and aChar s
 
ok, stepping over the call to replace
what is temp now?
 
8:26 AM
temp = temp.Replace(aChar.ToString(), "");
on the replace word?
 
step over that line
look at the temp variable, what does it contain now?
 
still 2014s
 
ok, then congratulations, you have the buggy version of .NET
 
@LasseV.Karlsen could u help me out with my question.... how do i populate my listview with a column from mysql table
 
no, I can't help you with your question
To be honest, the right place to ask programming questions is on the main site
 
8:28 AM
:|
 
but if the first thing that would happen is that it would be closed with "not enough information", then you need to add more information
 
Lasse V. team viewer wouldn't be better?..
 
I can't use team viewer here, I'm at work, team viewer usage here is logged
 
    private void textBox1_TextChanged(object sender, EventArgs e)
    {
        for (int i = 0; i < textBox1.Text.Length; i++)
        {
            if (Char.IsLetter(textBox1.Text[i]))
            {
                textBox1.Text = textBox1.Text.Remove(i, 1);
                textBox1.SelectionStart = textBox1.Text.Length;
            }
        }
    }
 
understand
 
8:29 AM
did you test that code @Shift?
 
didnt test it with copy paste :)
let me test with copy paste
 
what if you type in XX24
 
Shift, my textbox doesn't have SelectionStart..
 
what you mean "my textbox"?
 
it works also with copy paste
 
8:30 AM
I'm pretty sure that if you were using something other than the .NET textbox you probably would've said so
if you paste in XX24, does it work then?
 
typing and copy paste work with this code
 
it's c# .net but i created a control textbox
 
yes
 
did you try it?
 
it removes all letters
 
8:30 AM
or are you assuming?
 
is there any other code to replace this line? textBox1.SelectionStart = textBox1.Text.Length;
because i don't have SelectionStart..
 
we dont know what kind of methods your textbox have
has
 
@Shift how do i populate my listview with a column from mysql table?
 
@Brian, I'm pretty sure that if people could/wanted to help you, they would
 
listvite.items.add
 
8:33 AM
I'm also pretty sure that with 8 active people in this channel, you don't want 7 "no" when you ask a question, so the fact that nobody answers probably means that nobody can help you
 
private TextBox Base;
public NSTextBox()
{
SetStyle((ControlStyles)139286, true);
SetStyle(ControlStyles.Selectable, true);

Cursor = Cursors.IBeam;

Base = new TextBox();
Base.Font = Font;
Base.Text = Text;
Base.MaxLength = _MaxLength;
Base.Multiline = _Multiline;
Base.ReadOnly = _ReadOnly;
Base.UseSystemPasswordChar = _UseSystemPasswordChar;

Base.ForeColor = Color.White;
Base.BackColor = Color.FromArgb(50, 50, 50);

Base.BorderStyle = BorderStyle.None;

Base.Location = new Point(5, 5);
Base.Width = Width - 14;
 
And as I tried to hint before, your question doesn't have enough information. We have no idea what the actual problem is. Do you even know how to retrieve data from mysql?
 
ya @LasseV.Karlsen check the link
 
did you set the listview to show detail?
 
I did, I see a question with an answer.
 
8:38 AM
@Brian you need to add a listview header manually and set the mode to detail
then you will see 1 column
 
I wish to make a question. I made a project on human resource management. I know a little about ms sql and entity framework. As I'm new in .NET world, what should be my next target to learn. I'm a student. could anyone give me some suggestion? please..
 
@shift thanks it worked
 
@user3313264 if you hover over TextBox class does it point to System.Windows.Forms.TextBox ?
@Brian np
 
yes
 
@shift it only shows a few rows and to view the rest of the rows i have to scroll down. is there anyway that the listview could resize itself so that i can view all the rows without scrolling
 
8:41 AM
then my code should work
what framework version?
 
4.0
ase = new TextBox();
Base.Font = Font;
Base.Text = Text;
Base.MaxLength = _MaxLength;
Base.Multiline = _Multiline;
Base.ReadOnly = _ReadOnly;
Base.UseSystemPasswordChar = _UseSystemPasswordChar;
 
4.0 must be ok
 
this in on textbox
should i create Base.SelectionStart equals with what?
 
remove the selectionstart then test the code
@Brian what do you mean with resize? resize horizontally? or vertically
 
Shift it says the same thing: An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.dll
 
8:44 AM
@Shift vertically to display all retrieve rows
 
and it points me here: public override string Text
{
get { return base.Text; }
set
{
base.Text = value;
if (Base != null)
{
Base.Text = value;
}
}
}
 
what is base, what do you inherit from?
 
then you need to change the view layout from detail to other
 
Shift, can you come with team viewer?
 
hehe
 
8:46 AM
please? ^^
 
did you change the view mode to list
 
whats the code for that?
 
in the properties panel
user123821387021831092
 
got it
 
did you test the code without the selectionstart
 
8:48 AM
yes and it says what i last typed
above
 
what is base, what do you inherit from?
 
base = defines the base class for controls
 
I know what base means
which class do you inherit from?
 
textbox
 
so you are inheriting from TextBox, and you also have a private TextBox?
You have 2 textboxes in play then?
 
8:50 AM
no no no
i don't know very well english
 
public class NSTextBox : XXX <-- what does it say here in your code?
 
@Shift u mentioned earlier to set the listview to show detail. how to i do that?
 
class NSTextBox : Control
Lasse V. i putted the nstextbox code in a txt file
if this helps...i can't explain in english very good
Shift you can see it too?
 
As already established, the problem is with Replace
and that event handler
 

« first day (1276 days earlier)      last day (3687 days later) »