|
Alrighty, thanks!
(I feel even dumber having forgot about OnPaint... blasted semester finals...)
-Daniel
|
|
|
|
|
I am a huge C# newb trying to learn how to write a simple program. I am having a problem copying a file to another directory.
Lets say i copy C:\test.exe to C:\copy\text.exe. The file copys to the right folder but it ends up with both files having 0 bytes.
any help would be appreciated
Private void button6_Click(object sender, EventArgs e)
{
string path = textbox1.text
string path = textbox2.text
try
{
using (FileStream fs = File.Create(path))
File.Delete(path2);
File.Copy(path, path2);
textbox3.text = "file is copied"
}
catch
{
textbox3.text = "error"
}
}
Don't be overcome by evil, but overcome evil with good
-- modified at 18:44 Tuesday 25th April, 2006
|
|
|
|
|
That's because you are overwriting the source file! Just delete these two lines, there are unnecessary:
using (FileStream fs = File.Create(path))
File.Delete(path2);
File.Copy is the only line you need to use within the try catch. If you want to allow overwrites of exsiting files you can add true as a third parameter.
Regards, Graham.
|
|
|
|
|
Thanks alot man i appreciate it alot. It works perfect.
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Take a look at these two lines:
string path = textbox1.text<br />
string path = textbox2.text
You can't create two variables with the same name, so obviously this is not the code that you are actually using.
Assuming the rest of the code is at least reasonably similar to the one that you are using:
You create a new file but you are not writing anything to it. Of course the length of the file will be zero.
---
b { font-weight: normal; }
|
|
|
|
|
i accidently made a typo there. that wasn't what i had in my original code. It was path2 for textbox2.text.
thanks for you help tho
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
I have a DataGrid that uses a DataTable as its source of information to display and looks something like this:
Name Black_Car Brown_Car Red_Car
Ted 8 4 6
Jim 3 1 0
Bob 14 0 2
Total 25 5 8
Each Black_Car, Brown_Car, Red_Car, and Name column name is a link that sort the column in descending order when clicked. What I would like to do is add one more row at the bottom that say "Total" in the Name column and the sum for the other three columns. I was able to add the "Total" row with the sums, but whenever I click the column name link to resort, the "Total" row with the sums would be resorted also. I don't want the "Total" row to be resorted, I want it to always remain at the bottom of the table. I would really appreciate any help, thanks.
-- modified at 17:35 Tuesday 25th April, 2006
|
|
|
|
|
Hi,
the DataGrid doesn't have any inbuilt functionality to achieve what you want. But probably we can find a workaround. For this it is important to describe a bit more:
1. Should your grid be editable by the user?
2. Is the table filled via some sort of database connection or are you filling it manually?
|
|
|
|
|
The DataGrid is not editable by the user and the table is filled by reading in values from a text file.
|
|
|
|
|
I am new to dotnet developement so please excuse me if this has been answered before.
I need to change a textbox to a listbox or other type container at runtime based on user config options specified in a database.
The user will specify through another app the fields that they want activated, the type the field should be (check box, list box, date - calendar, number field etc). For list boxes, they will specify the list of values. They will also specify where on the container the item should be placed. All these specifications will be in a datagrid that I need to loop through at runtime and place the items in the appropriate container at the specified location and set up the display attributes (list box, check box etc)
Any help\ideas will be appreciated
|
|
|
|
|
To add controls dynamically, just call their constructor, set their properties, such as position, and add them to the Controls collection on the form. You can't *change* the type of a control, you need to either put all the controls you may need on the form, and show/hide them with the Visible property, or create them dynamically. They won't be member variables then, you'd need to search for them in the controls collection to do anything with them, or put them in a container of your own.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks for the reply! I understand.
I want to be able to add the item to a specific page on a tabconrol. I assume I will have to use the parent method? But I am not sure how to do that?
TextBox mytext = new TextBox();
mytext.Name = myrow["FIELD_NAME"].ToString();
mytext.Parent = this.tabControl1. ??????
|
|
|
|
|
No, it's this.tabControl1.Controls.Add(mytext);
You still need to set the position and size of the control, at a minimum. I believe the Visible property defaults to true, but it's worth making sure.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi there!
Is it possible to retieve user nt name from the web request? This question
arose while thinking about authentication system implementation in the
asp.net.
my code --- string UserID = User.Identity.Name;
which returns Domainname\Userid
I want to make authentication process transparent for the user. E.g. if the
user is logged on the domain or is a member of the domain then perform
authentication autimatically - as a result user won't experience any login
windows, otherwise web-app will provide the form similar the IIS one for
authentication.
Can this be done from the web application?
Thanks in Advance
Krishna
|
|
|
|
|
Have you turned on the Impersonation ?
http://www.routeservices.com
|
|
|
|
|
Hi,
I've made Indentity Impersonation = "true" in webconfig, still im getting windows authentication login window.
|
|
|
|
|
Hi all!
I need a way to get all the groups of the AD to list.
I get the code of Umar_hasan at: http://www.codeproject.com/csharp/adtester.asp, but is not working in a WebForm... Anybody knows how I can do this?
|
|
|
|
|
As you're using ASP.NET, you'll be listing active directory stuff on the server, not on the client. Your code runs on the server.
What do you mean by 'not working' ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi, I have 3 Solutions programmed in C#.
The first one is an assembly, a dll, that is used by applications in the other two Solutions.
I'd like to know if there's a way to debug my applications and trace into the code of the dll without rearranging my Solutions (i.e. without moving my application projects into the first Solution).
Thanks!
|
|
|
|
|
Instead of referencing the dll from the other two solutions, add the project to the other two solutions also, and reference the project.
---
b { font-weight: normal; }
|
|
|
|
|
I have a C# windows app. It looks like:
public class FormA
{
private ScanFile_Click
{
bool bSuccess = FormB.DoProcess("C:\textfile.txt");
}
}
public class FormB
{
public FormB
{
InitializeComponent();
}
public static bool DoProcess(string sInputFile)
{
FormB frmLocate= new FormB();
frmLocate.Show(frmParent);
// I want the new thread to finish processing before it comes to the statement below
// so that I can return the correct value to FormA
if(frmLocate.SuccessParsing)
{
strFileDetails = frmLocate.FileDetailArray;
}
return frmLocate.SuccessParsing;
}
private void OnLoad()
{
ParseDelegate calcPi = new ParseDelegate(ParseFile);
calcPi.BeginInvoke(this.m_sInputFile, null, null); // calling a new thread
}
// Worker thread
private void ParseFile(string sInputFile)
{
/* Do some calculations here */
/* I need to periodically update GUI controls */
}
My application is more like the one described in
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms06112002.asp
except that i do not have a button to start the new thread but i have to start the worker thread on load (like shown in my previous comment) and the worker thread communicates with the GUI thread (main thread) (in the ParseFile method ). After the worker thread finishes its work the DoProcess method must exit returning the result.
How should i proceed? Or Is there a better way of doing this?
|
|
|
|
|
You can call theOtherThread.Join to force some thread to finish executing.
Since you're doing UI communication, I recommend you use the System.ComponentModel.BackgroundWorker component; this will fire a "work in the background" event (DoWork event) which will run on a background thread. Then another event (the RunWorkerCompleted event) will fire when the work is done; firing on the UI thread. Thus, it allows you to do multithreading without having to do manual thread joins, UI control invokation and so on.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Is Jesus the Jewish Messiah?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
I am trying to communicate between two app domains which my application process has. Two questions...
1. Is .net remoting the best way to communicate an invocation between these two app domains?
2. Is IPC the best type of channel, when the communication will (must in fact) never go outside of my process?
Joel Holdsworth
Want to give me a job this summer?
Take a look at my online CV
|
|
|
|
|
Maybe this answers at least one of your questions: Ingo Rammer (a .NET remoting guru) states on his blog [^],
"As soon as you create a new application domain in .NET, you are automatically using Remoting behind the scenes to communicate between the two AppDomains. In this case, the Remoting framework will setup all channels and sinks for you - and in fact it will use a highly optimized formatting process and an in-memory channel.
This provides for two different implications: a) you can't change formatters or channel sink chains and b) you don't have to care too much about it. It just works. You can use all .NET Remoting features without any problems.
In fact, cross-AppDomain calls are one of the primary use cases for .NET Remoting. They are so well integrated in the framework, that you usually don't even notice that you are using Remoting."
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Is Jesus the Jewish Messiah?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Hmm ok, that's helpful. The reason I ask is that I'm writing a manged plugin for an unmanged application with a MC++ bridging dll and a C# worker dll. So far things have been fairly simple - the bridging dll has a "Run" method which gets called by the host when it's time to do work, and then the whole of the plugin operates within that single app domain. However I get problems when I need to handle callbacks from the host, because .net seems to give these functions a fresh app domain. So I need to figure out how to use remoting (or whatever) to forward the event into the main app domain.
Joel Holdsworth
Want to give me a job this summer?
Take a look at my online CV
|
|
|
|