|
How can I delete a specific Excel File in my own directory using C#?
|
|
|
|
|
You already have the correct verb[^].
|
|
|
|
|
if (System.IO.File.Exists(physicalpath+filename))
{
System.IO.File.Delete(physicalpath+filename);
}
|
|
|
|
|
hello guys. I think this is the right platform to ask this question and am sure most of you must have worked in MFC / VC++ as well.
I want to know that how a control knows about its event handler ( and any associated variable)? Let's say I add an event handler OnClick_Save to the button named btnSave. How does this button knows about this event handler.
In MFC, this thing can be understood by having a look at MessageMaps and DoDataExchange().
Thanks for providing any detailed input or pointer on this issue.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
It's a property of the object's class and managed internally by the .NET framework.
|
|
|
|
|
Under the hood (the topmost hood of many, that is) you subscribe a method to the control's OnClick event. In code that would mean something like
btnSave.Click += new System.EventHandler(OnClick_Save);
It's hidden away from you in the corresponding [InsertFormNameHere].designer.cs file.
The above mentioned "Click" holds a list of methods to call whenever the OnClick event is raised. You can also unsubscribe a method from that list. Or subscribe many methods (as a list would suggest).
This is a very basic explanation. I'm sure someone can provide more in-depth knowledge if required.
Ciao,
luker
|
|
|
|
|
Delegates hold a list of delegates (called an invocation list) which are called when the delegate itself is invoked.
The += YourMethod adds a delegate to your method to the event's (an event is just a specialized delegate) invocation list.
using System;
public class EventRaisingClass
{
public event EventHandler SomethingChanged;
public void ChangeSomething()
{
OnSomethingChanged(EventArgs.Empty);
}
protected virtual void OnSomethingChanged(EventArgs e)
{
EventHandler eh = SomethingChanged;
if (eh != null)
eh(this, e);
}
}
using System;
public class SubscribingClass
{
private EventRaisingClass eventRaisingInstance;
public SubscribingClass()
{
eventRaisingInstance = new EventRaisingClass();
eventRaisingInstance.SomethingChanged += EventRaisingInstanceSomethingChanged;
}
private void EventRaisingInstanceSomethingChanged(object sender, EventArgs e)
{
Console.WriteLine("Something Changed");
}
public void Update()
{
eventRaisingInstance.ChangeSomething();
}
}
In your example the Button is the EventRaisingClass, that code is part of the framework but operates in exactly the same way.
Warning: Because a reference to an item (method) of our subscribing class is now held in another class instance, it will not be eligible garbage collection until the raising class instance is collected. If you require the subscribing instance to be eligible for collection beore that time then you can remove the delegate from the event with -= YourMethod . Not needed often, but can cause suprises if you are not aware of this.
|
|
|
|
|
A fine explanation. One question though. How / Where Update() is called here?
This world is going to explode due to international politics, SOON.
|
|
|
|
|
It's not in the sample code, but it could be called from anywhere that has access to an instance of that class (or by code elsewhere within the class).
|
|
|
|
|
Hello everybody. im working on graduation project and i have trouble to locate and find iris image. where can i find libraries to find iris image? please answer this very important for me i must graduate this year but i can't finished my project yet.
|
|
|
|
|
A quick Google search for "face recognition" or "eye recognition" will probably find what you are looking for.
|
|
|
|
|
Hi All,
Firstly I don't want to post in wrong forum for set up, installer questions which this is I have posted here until I can find a more approiate forum on CP. I have an executable I have written/hacked with help to test for a driver, I would like to know how to ensure it gets excuted by the installer (this is related to question I asked Pete O'Hanland last week I am NOT trying to do anything nasty!).
Glenn
|
|
|
|
|
I would execute it as part of a custom installer step. You can find an example of code here[^] that starts an external process.
|
|
|
|
|
Thanks for that, is there a forum on CP for installers and things, the closest I found was System Admin?
Glenn
|
|
|
|
|
There isn't. This form has been regularly used for installer questions, so I think we can cut you a little slack.
|
|
|
|
|
Bit OT but is MIL OK?
Glenn
|
|
|
|
|
Well, she had the operation yesterday, and according to the nurses, they've removed the bits they needed to remove. Unfortunately we could get no more details because this was last night, so we're waiting to speak to her consultant today for more details. She's hooked up to the pain meds, so we're hoping that she's had a comfortable night.
Thanks for asking.
|
|
|
|
|
No Worries! been there myself (don't really want to go there again but...)
Glenn
|
|
|
|
|
i want make a class for use textbox act as masketextbox
|
|
|
|
|
You already have a Masked Text Box control available[^].
You should not need to create a separate control unless this is for academic purposes.
|
|
|
|
|
What technology? ASP.NET? WPF? Windows Forms? Silverlight?
|
|
|
|
|
|
I have created an interface where user can chose the required data to be exported to excel.
If in future, user select a new data to be exported which the new data is already included in the previous data, the excel file must not replace bt the current one. If the new data selected is not included in the previous data, the excel file should update the data instead of replace it.
Any idea of how can I do that?
|
|
|
|
|
Member 9169887 wrote: Any idea of how can I do that?
Open your excel file, loop through all existing data and see whether it has changed (and needs be updated)
Easiest way to read an existing excel-file would be using JET.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
I AM CREATING A QUERY SORTER IN WPF C# ...
FOR THIS I USED DATAGRID AND IN DATAGRID TEMPLATE COLUMN I USED AN IMAGE(BLANK.BMP). ON CLICKING, I WANT BLANK.BMP TO BE CHANGED INTO ASCENDING.BMP , AND ASCENDING.BMP TO DESCENDING.BMP , AND DESCENDING.BMO TO BLANK.BMP. HOW CAN I PERFORM THIS FUNCTIONALITY OF IMAGE CHANGING IN DATAGRID??
|
|
|
|