|
I have a web application that references an access database in my app_data folder. Locally I can reference the db by C:/My Docs/Visual Studio 2005/Website/My Website/App_Data/myaccess.mdb
My question is, in my code how do I reference the database relatively since I do not know what drive and directories my site will be stored on? I've tried ~/App_Data/myaccess.mdb (tried this locally and it does not reference the db) and it does not connect. All suggestions welcome thanks.
|
|
|
|
|
|
I'm not exactly sure how to incorporate this into my connection string
//create an open string
string conString = @"Provider=Microsoft.JET.OLEDB.4.0;" + @"data source=C:\Documents and Settings\My Name\My Documents\Visual Studio 2005\WebSites\MySite\App_Data\td.mdb";
i've tried
@"data source=" + Server.MapPath("http://www.mywebsite.com/App_Data/td.mdb");
and get an error.
Please advise. Thanks.
|
|
|
|
|
The MapPath method takes a virtual path, not a complete url. Use just "/App_Data/td.mdb".
dboy221 wrote: and get an error.
That is way too specific. Could you be a bit more vague, please?
---
single minded; short sighted; long gone;
|
|
|
|
|
That did it. Thanks guys.
|
|
|
|
|
Hi.
I need to capture the event when the mouse leaves the panel and its left button pressed.
Can anyone help me with this?
What should i do?To write my own wndProc or ...?
Thank You.
|
|
|
|
|
You can capture the mouse, and then you will get mouse messages even when the mouse leaves your control. Then, you can capture the button click and check if the mouse is over the panel. If not, you have your event. You would then release capture of the mouse, so that the events would be passed to other controls after that.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Ok, and how i should to capture the mouse buttons click?
|
|
|
|
|
The point of capturing the mouse, is that the click event will be fired in your control, even if the mouse has left it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
i have about 100 dynamically generated panels.
And i need for example press the left-mouse button on the one and then just drag the cursor down and all panels which will be on my way for example must change the color.
I think that now it is more understood able.
|
|
|
|
|
OK, sounds like you need to be handling events in the parent form, not the panel.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
i have a greduation work about real time simulation.i have already modeled my robot arm on 3d max studio and i have XAML converter.but i dont know how to write my code in visual c#.net.what must i do?i have net framework 3.how can i simulate my robot arm with visual c#?please anyone writes step by step.
|
|
|
|
|
If you have a XAML converter, then I'd guess you have your model in XAML, so it shows in WPF. The next step, is to write the code that moves it. Really, your question is both too vague, and too broad for you to expect an answer in a forum to solve your issue for you. I'm not even clear on if you know the first thing about C#, if you know more about WPF than you saw in an ad somewhere, or what skills you're bringing to the table, you just sound like a confused guy who knows some buzzwords and is hoping for a magic bullet.
So, try asking your question more clearly, the answer will probably be, try to write it and ask specific questions when you get stuck.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
1)i have modeled my robot arm.
2)than i export it to XAML
which platform will i use for doing WPF project?
visual c# is enough for me?or will i use another platform?(aurora and like this?)
can u write me step by step how can i do wpf simulation? which platform i need?and which converter can be better?ok: )i dont know anything about wpf and explain me as you try to write small baby(me: )) please can u write step by step how can i do wpf project?which platform will be used in simulation?
|
|
|
|
|
Hello
[url]http://www.csharp-station.com/Tutorials/Lesson14.aspx[/url]
[code]
using System;
using System.Drawing;
using System.Windows.forms;
// custom delegate
public delegate void Startdelegate();
class Eventdemo : form
{
// custom event
public event Startdelegate StartEvent;
public Eventdemo()
{
Button clickMe = new Button();
clickMe.Parent = this;
clickMe.Text = "Click Me";
clickMe.Location = new Point(
(ClientSize.Width - clickMe.Width) /2,
(ClientSize.Height - clickMe.Height)/2);
// an EventHandler delegate is assigned
// to the button's Click event
clickMe.Click += new EventHandler(OnClickMeClicked);
// our custom "Startdelegate" delegate is assigned
// to our custom "StartEvent" event.
StartEvent += new Startdelegate(OnStartEvent);
// fire our custom event
StartEvent();
}
// this method is called when the "clickMe" button is pressed
public void OnClickMeClicked(object sender, EventArgs ea)
{
MessageBox.Show("You Clicked My Button!");
}
// this method is called when the "StartEvent" Event is fired
public void OnStartEvent()
{
MessageBox.Show("I Just Started!");
}
static void Main(string[] args)
{
Application.Run(new Eventdemo());
}
}
[/code]
And this from :[url]http://www.codeguru.com/csharp/csharp/cs_delegates/eventhandling/[/url]
[code]
using System;
//Step 1 Create delegate object
public delegate void MyHandler1(object sender,MyEventArgs e);
public delegate void MyHandler2(object sender,MyEventArgs e);
//Step 2 Create event handler methods
class A{
public const string m_id="Class A";
public void OnHandler1(object sender,MyEventArgs e){
Console.WriteLine("I am in OnHandler1 and MyEventArgs is {0}",
e.m_id);
}
public void OnHandler2(object sender,MyEventArgs e){
Console.WriteLine("I am in OnHandler2 and MyEventArgs is {0}",
e.m_id);
}
//Step 3 create delegates, plug in the handler and register
// with the object that will fire the events
public A(B b){
MyHandler1 d1=new MyHandler1(OnHandler1);
MyHandler2 d2=new MyHandler2(OnHandler2);
b.Event1 +=d1;
b.Event2 +=d2;
}
}
//Step 4 Calls the encapsulated methods through the
// delegates (fires events)
class B{
public event MyHandler1 Event1;
public event MyHandler2 Event2;
public void FireEvent1(MyEventArgs e){
if(Event1 != null){
Event1(this,e);
}
}
public void FireEvent2(MyEventArgs e){
if(Event2 != null){
Event2(this,e);
}
}
}
public class MyEventArgs EventArgs{
public string m_id;
}
public class Driver{
public static void Main(){
B b= new B();
A a= new A(b);
MyEventArgs e1=new MyEventArgs();
MyEventArgs e2=new MyEventArgs();
e1.m_id ="Event args for event 1";
e2.m_id ="Event args for event 2";
b.FireEvent1(e1);
b.FireEvent2(e2);
}
}
[/code]
I have 2 questions,
In first example ,It didn't used
But in second example,It is used
Why?
When do we use EventArgs?
|
|
|
|
|
Hello
From Programming C#, 4th Edition
[code]
namespace EventKeyword
{
// a class to hold the information about the event
// in this case it will hold only information
// available in the clock class, but could hold
// additional state information
public class TimeInfoEventArgs : EventArgs
{
public readonly int hour;
public readonly int minute;
public readonly int second;
public TimeInfoEventArgs(int hour, int minute, int second)
{
this.hour = hour;
this.minute = minute;
this.second = second;
}
}
// our subject -- it is this class that other classes
// will observe. This class publishes one event:
// OnSecondChange. The observers subscribe to that event
public class Clock
{
private int hour;
private int minute;
private int second;
// the delegate the subscribers must implement
public delegate void SecondChangeHandler
(
object clock,
TimeInfoEventArgs timeInformation
);
// the keyword event controls access to the delegate
public event SecondChangeHandler OnSecondChange;
// set the clock running
// it will raise an event for each new second
public void Run( )
{
for(;;)
{
// sleep 10 milliseconds
Thread.Sleep(10);
// get the current time
System.DateTime dt = System.DateTime.Now;
// if the second has changed
// notify the subscribers
if (dt.Second != second)
{
// create the TimeInfoEventArgs object
// to pass to the subscriber
TimeInfoEventArgs timeInformation =
new TimeInfoEventArgs(
dt.Hour,dt.Minute,dt.Second);
// if anyone has subscribed, notify them
if (OnSecondChange != null)
{
OnSecondChange(
this,timeInformation);
}
}
// update the state
this.second = dt.Second;
this.minute = dt.Minute;
this.hour = dt.Hour;
}
}
}
// an observer. DisplayClock subscribes to the
// clock's events. The job of DisplayClock is
// to display the current time
public class DisplayClock
{
// given a clock, subscribe to
// its SecondChangeHandler event
public void Subscribe(Clock theClock)
{
theClock.OnSecondChange +=
new Clock.SecondChangeHandler(TimeHasChanged);
}
// the method that implements the
// delegated functionality
public void TimeHasChanged(
object theClock, TimeInfoEventArgs ti)
{
Console.WriteLine("Current Time: {0}:{1}:{2}",
ti.hour.ToString( ),
ti.minute.ToString( ),
ti.second.ToString( ));
}
}
// a second subscriber whose job is to write to a file
public class LogCurrentTime
{
public void Subscribe(Clock theClock)
{
theClock.OnSecondChange +=
new Clock.SecondChangeHandler(WriteLogEntry);
}
// This method should write to a file.
// We write to the console to see the effect.
// This object keeps no state.
public void WriteLogEntry(
object theClock, TimeInfoEventArgs ti)
{
Console.WriteLine("Logging to file: {0}:{1}:{2}",
ti.hour.ToString( ),
ti.minute.ToString( ),
ti.second.ToString( ));
}
}
public class Test
{
public static void Main( )
{
// create a new clock
Clock theClock = new Clock( );
// create the display and tell it to
// subscribe to the clock just created
DisplayClock dc = new DisplayClock( );
dc.Subscribe( theClock );
// create a Log object and tell it
// to subscribe to the clock
LogCurrentTime lct = new LogCurrentTime( );
lct.Subscribe( theClock );
// Get the clock started
theClock.Run( );
}
}
}
[/code]
May someone explain about this part of code:
[code]
if (OnSecondChange != null)
{
OnSecondChange(
this,timeInformation);
}
}
[/code]
I don't know but I think,But I think it should be something like this:
Onsecondchange =+new secondchangehandler(funcname)...
|
|
|
|
|
|
Hello
about this:
[code]
public void OnHandler1(object sender,MyEventArgs e)
[/code]
May someone explain it?
[url]http://www.codeguru.com/csharp/csharp/cs_delegates/eventhandling/[/url]
|
|
|
|
|
Custom EventArgs are used when you need to pass additional information to the subscriber.
You don't use custom event args in cases where you just want to know something happened such as a button click. You know its a button and its been clicked.
You use custom event args if you want more info about the event say if you want to know the background color of the button.
public class MyEventArgs : EventArgs
{
public Color btnColor;
public MyEventArgs(Color color)
{
btnColor = color;
}
}
then when you create;
if (myHandler != null)
myHandler(this, new MyEventArgs(button1.BackColor);
Hope this helps
Mike
Everybody gotta be somebody
|
|
|
|
|
I am trying to create a self updating application. I am sure that you have heard of .Net Reflector.
It is a single exe which has the ability to update it self. Oddly enough it you try to use Reflector on itself it has be ofuscated. So, I can't see what he has done.
Here is how it works.
1. You start up the app and it detects that it needs an update.
2. It appears to shut itself down, download the updated exe and then restarts it.
It you watch the process list you will see that during the update process he spawns (starts...)
a process called tmp6E.exe, which I am guessing does the work.
I have coded up a solution but it doesn't work correctly.
1. I embedded an update.exe program in my main app which does the updating, which works fine.
2. I have tried not using it embedded but I still have the same problem.
How do you start/spawn a process and then shut down the parent (calling app) so that you can
over write it?
|
|
|
|
|
Probably with Process.Start, I'd imagine a call to Procss.Start followed by this.Close() would not close the spawned process.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
That's what I tried first. But it doesn't work.
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1()); <<<---- exception here.
}
I get the following exception
{"Cannot access a disposed object.\r\nObject name: 'Form1'."}
|
|
|
|
|
When do you get this exception ? What do you do to restart Main, or do you just get it when you run the app the second time ? If so, how do you run it ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Okay, I found part of my problem. First let me explain what I am trying to do.
I currently have two exe's.
1. MainApp.exe (has two forms the main form and an update form)
2. Update.exe
When MainApp.exe starts up it downloads a file from one of my web pages (version.txt)
it currently contains 2.0.0.0. I then compare my current version which is 1.0.0.0 and
if the version on the server is larger than my current version I create an instance
of my update form which says "There is an update available do you want to automatically
update?". If you click no I just close the update form and then the main form is shown.
If you click yes, I close the update form and I start the update.exe as a process.
Then I want to exit out of the MainApp.exe and let update.exe download the update
replacing the current out of date one.
My first problem is that I was doing this logic inside the MainForm constructor. If you
attempt to call this.Close() the form has even finished creating itself and thus my problem.
My next problem seems that I am in a continuous loop calling my update form in the MainApp over
and over again.
|
|
|
|
|
The easiest thing to do would be to load your assembly (assemblies) in a shadow cache - this is a little known feature of .NET that copies your assemblies to a temporary directory before executing them. This is done explicitly for the purpose you are asking - software updates - but also for some other, very obscure security reasons that I don't fully understand myself.
At any rate, I first learned of the approach from the Morrison Schartz plugin manager, so you might download their plugin source code and take a look. There are also several articles here on Code Project that use a strikingly similar approach, so they would be good to look at (search for "application auto-update").
For the Morrison Schwartz approach, go here: http://www.ms-inc.net/dotnet.aspx?ProductID=Plugins
|
|
|
|