|
|
I know that there is a possibility to get the name of the file after choosing it in the FileDialog, like this:
String str=fileDialog1.fileName()
The String(str) includes the full address of the file.
for example:
str="c:\windows\system\abc.txt"
but i want only the file name(abc.txt).
how can i receive only the file name and not the full address?
thank you
G.
|
|
|
|
|
use safefilename like this
DialogResult dr= openFileDialog1.ShowDialog();
if(dr==DialogResult.OK)
MessageBox.Show(openFileDialog1.SafeFileName);
|
|
|
|
|
Try Path.GetFileName[^] passing the full path you get from the file dialog. Also see other static methods in the Path[^] class in case you are interested.
|
|
|
|
|
hi,
you can also use 'FileInfo' class to get some information of your file in the given path.
|
|
|
|
|
If I have method with a non void return type is there a way to make the compiler check that the returned value has been explicitly assigned?
e.g.
When the method signature is
int DoSomething(int inValue);
Can the intended usage of
int retVal = DoSomething(iv);
in contrast to
DoSomething(iv);
actually be enforced.
I'd like a compiler warning for this situation but I haven't found one.
Alan.
|
|
|
|
|
Hi,
there is no such thing, a method will execute when called, whether the return value is
used somehow or not; so you can not enforce its use.
The situation is different with a property: you can not invoke a property unless
you either assign it a value (setter) or read AND use its value (getter).
|
|
|
|
|
Thanks for the response. You confirmed that the situation is as I had thought it to be, in that the use of the returned value is optional and cannot be checked.
Alan.
|
|
|
|
|
How may I add an swf file into a web application in aspx file so that it will start running when an specific buttun is pressed(a button except of the swf link).
|
|
|
|
|
I'm not sure how to communicate between swf and asp events but one approach could be for example displaying an image instead of swf and when the button is pressed load the swf by any mean you want
I Wish the Life Had CTRL-Z
Wizard's First Rule : People are fool,they believe what they want to believe or what they afraid to believe
www.subaitech.blogspot.com
|
|
|
|
|
My Code in C#:
Object o1=new Object();
Object o2;
How can i copy the o2 object to be exactly like o1( no a reference. o2=o1 is reference).
i tried o2.copy(o1) or something like this but the method "copy" does not exist ;
Can you help me?
|
|
|
|
|
You can create an exact copy of the object using Clone() method if that type implements ICloneable interface
Do more work
Make more mistakes
Learn more things
|
|
|
|
|
by the way, i am using Visual Studio 2008.
what do you mean type? which type?
i added "ICloneable" here:
public partial class Form1 : Form,ICloneable
{
Object o1=new Object();
Object o2;
}
Thanks you
|
|
|
|
|
Admin887 wrote: // o2.clone() does not exist
It doesn't help if you appear to be angry with the person that tried to help you. Especially, when it seems you have misunderstood that assistance.
You cannot clone a System.Object because it does not implement ICloneable . Adding it to the Form1 class will not help, it only demands that you provide an implementation for the Form1 class.
Admin887 wrote: what do you mean type? which type?
A "type" in .NET can be a class, a struct, an enum, and so on.
The "type" the person was referring to was the type of the object which you are trying to clone. You can only add ICloneable to types that you create. You cannot add it to existing types.
Now, what do you really want to do? Creating a System.Object is generally not a very useful thing to do.
|
|
|
|
|
First of all, i am very sorry, really.unintentionally i added this smile. I do not mean it. i am very nice guy
And now to the question:
I created a GroupBox(groupBox1) that contains textBox and buttons(i created this with the design option on the Form).
i want to create a new Tab(only with code without designing) that contains gruopBox(g) exactly like groupbox1.
GroupBox g = new GroupBox();
Thank you for your attention
G.
modified on Sunday, June 29, 2008 5:30 AM
|
|
|
|
|
Hello all
I am hoping someone can help me here as I have been asked to write a little application which will report on the machine it is installed information such as operating system, ram, pagefile, whether oracle is installed and what version, etc, etc
I was hoping people would have any useful suggestions of how they think I can get all this information using C# as I am not sure, I was thinking of maybe the registy for some things but was hoping someone had some better suggestions.
Thanks in advance for any help that can be offered
|
|
|
|
|
Hey all, first-time-poster long-time-reader, etc.
I have already managed to use CryptoStream and FileStream to encrypt an individual image into another single file, and also then used CryptoStream, MemoryStream and then Image to decrypt and display the image in a picturebox on a form. This way none of the data is actually stored, unencrypted, on the hard drive (unless the user hibernates the machine with it in memory) - this is very important.
However, what I want to do is to 'import' multiple images into one (preferably compressed) file - so I need to concatenate them somehow and then run compression on them. This file needs to then be able to be unencrypted, decompressed and split back into the respective images, providing the user the ability to view each image.
Please note: I can't use temporary files, everything up until the saving of the one main encrypted file needs to be done in memory.
I don't know where to start, just wondering if anyone could point me in the right direction?
|
|
|
|
|
Hi friends.
I have a XML file like this :
<?xml version="1.0" encoding="utf-8"?>
<root ELEMENTS="11">
<BOOKMARK1 ID="1" />
<BOOKMARK1 ID="2" />
<BOOKMARK1 ID="3" />
<BOOKMARK1 ID="4" />
<BOOKMARK1 ID="5" />
<BOOKMARK1 ID="6" />
<BOOKMARK1 ID="7" />
<BOOKMARK1 ID="8" />
<BOOKMARK1 ID="9" />
<BOOKMARK1 ID="10" />
<BOOKMARK1 ID="11" />
</root> ;
I want select root's ELEMENTS attribute value.
I used this code :
X_Element = XElement.Load(FileName);
MessageBox.Show(X_Element.Nodes().First().Parent.Attribute("ELEMENTS").Value.ToString());
Is there a better way or this way is good for my work ?
Freshman
|
|
|
|
|
M-Dayyan wrote: Is there a better way or this way is good for my work ?
Yes, you need to pay attention to what you are doing and to what each of the objects already are.
I'm curious to know what your thought process of this was:
X_Element.Nodes().First().Parent
Becuase all that code does is get you back to the starting point. In other words:
X_Element == X_Element.Nodes().First().Parent
Also, the Value property on XAtribute already returns a string , so why redundantly call ToString() on it again?
Your code could be reduced to:
X_Element.Attribute("ELEMENTS").Value
|
|
|
|
|
Great.
Thank you.
Freshman
|
|
|
|
|
i want to create crystal report in run time, means through C# hard code
|
|
|
|
|
prakash_adysoft wrote: run time
prakash_adysoft wrote: hard code
Surely that is mutually exclusive. If you hard code something the it is set at compile time, not at runtime.
|
|
|
|
|
Hi all,
I am really stumped on this one so really appreciate any help.
I have a .net service which during OnStart creates a Process() to another .NET exe which I want to display a notify icon in the system tray and show a form. However the Main(string[] args) event in the exe is not firing even though the process is started (exe exists as process in Task Manager) All this code works from another Test exe but not the service. (Full Code Below). I have updated the registrykey for the service to allow this but have had no imrovement.
Cheers
Stu
*****Service*****
protected override void OnStart(string[] args)
{
System.IO.StreamWriter sw = new System.IO.StreamWriter(@"C:\CodeDir\KnowledgeAssist\KAClientManager\bin\Debug\Test1.txt", true);
sw.WriteLine("0");
try
{
Process notify = new Process();
notify.StartInfo.FileName = @"C:\CodeDir\KnowledgeAssist\KANotify\bin\Debug\KANotify.exe";
notify.Start();
sw.WriteLine("1");
}
catch(Exception ex)
{
sw.WriteLine(ex.Message);
}
sw.Close();
}
*****EXE*****
public static void Main(string[] args)
{
//new TrayIcon();
System.IO.StreamWriter sw = new System.IO.StreamWriter(@"C:\CodeDir\KnowledgeAssist\KAClientManager\bin\Debug\Test1.txt", true);
sw.WriteLine("Main");
sw.Close();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
|
|
|
|
|
Services run on their own desktop. The exe you launched is running on another desktop so you can't see it.
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
Hi all,
Doing an app which enables me to write a message and send it via email. I chose to use my gmail account. Here is the code...
private void button1_Click(object sender, EventArgs e)
{
try
{
MailMessage mail = new MailMessage("fromMe@gmail.com", "toRecipient@hotmail.com", "testing subject here", txtMessage.Text);
SmtpClient emailClient = new SmtpClient("smtp.gmail.com",586);
System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential("myusernameHere@gmail.com", "mypasswordHere");
emailClient.UseDefaultCredentials = true;
emailClient.Credentials = SMTPUserInfo;
emailClient.Send(mail);
lblStatus.Text = "email sent";
}
catch (Exception ex)
{
lblStatus.Text = ex.Message;
}
}
I keep getting a "Failure sending mail" exception.... something must be missing or wrong... any ideas please? Cheers
|
|
|
|