|
hi all,
i am working in windows form, i couldn't reach to the destination file when in use(""..\\..\file name");
which method should i use to reach to a perticular dirctory of my machine,
i know in web i used to use server.mappath...but here i don't know,
bye byes
prashanth
|
|
|
|
|
if u want to know the application path of ur program then u can use
Application.StartupPath;
rahul
|
|
|
|
|
Hi
You can get using Application instead of Server. Try this
Application.StartupPath.ToString(); -> this will give the current application path.
There are some properties for the class Application like:
- ExecutablePath
- LocalUserAppDataPath
Hope this helps you.
Harini
|
|
|
|
|
Harini Krishnaswamy wrote: Application.StartupPath.ToString();
Application.StartupPath is already a string . Why do you put .ToString() on the end of it?
|
|
|
|
|
Hi Colin,
You are right. No need to give ToString(). Application.StartupPath is enough.
Harini
|
|
|
|
|
Hi
I am trying to develope an Utility to handle reporting of errors and exceptions in my application. Whenever an exception occurs I want the exception details to be written to a XML file.
I am using the following code, but it does not append to the file, it overwrites the previous data. How can I have the new exceptions append to the file so that I have a full history of all the exceptions without having to create a new file each time?
private static void LogException_XML(DateTime date, string fullpath, string localPath, Exception e)<br />
{<br />
try<br />
{<br />
XmlWriterSettings settings = new XmlWriterSettings();<br />
settings.Indent = true;<br />
settings.IndentChars = (" ");<br />
using (XmlWriter writer = XmlWriter.Create(fullpath, settings))<br />
{<br />
writer.WriteStartElement("Exception");<br />
writer.WriteElementString("Date", date.ToShortDateString());<br />
writer.WriteElementString("Time", date.ToShortTimeString());<br />
writer.WriteElementString("Message", e.Message);<br />
writer.WriteElementString("Source", e.Source);<br />
writer.WriteElementString("Stacktrace", e.StackTrace);<br />
writer.WriteElementString("TargetSite", e.TargetSite.ToString());<br />
writer.WriteElementString("TargetSite", e.TargetSite.ToString());<br />
writer.WriteEndElement();<br />
writer.Flush();<br />
}<br />
<br />
}<br />
catch (Exception ex)<br />
{<br />
throw ex;<br />
}<br />
}
Thanks.
Kobus
|
|
|
|
|
You could use an overload of the XmlWriter.Create method that takes a Stream instance instead of the filepath and explicitely create a FileStream that appends to the file, but this will create invalid XML since an XML document must have a single root element. I'm not sure how hard it is to position the XmlWriter in a way that you will overwrite the closing root element tag, so I recommend the XmlDocument class.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Dear all,
How would I be able to generate MS project File in C# ?
Lq
|
|
|
|
|
I've got a remoting based application up and running (basically a client app that uses a custom server to access a database, etc), and it seems to do everything fine as long as the client and server are on the same Windows domain.
Unfortunately it also needs to be used on another domain within the company (both domains can see each other, btw).
When the client application is run on the other network, I get the following exception:
=============================================================================
InvalidCredentialException: The server has rejected the client credentials.
Stack Trace:
Server Stack Trace:
at System.Net.Security.NegoState.ProcessAuthentication(LazyAsyncResult lazyResult)
at System.Net.Security.NegotiateStream.AuthenticateAsClient(NetworkCredential credential, String targetName, ProtectionLevel requiredProtectionLevel, TokenImpersonationLevel allowedImpersonationLevel)
at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.CreateAuthenticatedStream(Stream netStream, String machinePortAndSid)
at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.CreateSocketHandler(Socket socket, SocketCache socketCache, String machinePortAndSid)
at System.Runtime.Remoting.Channels.SocketCache.CreateSocketHandler(Socket socket, String machineAndPort)
at System.Runtime.Remoting.Channels.RemoteConnection.CreateNewSocket(EndPoint ipEndPoint)
at System.Runtime.Remoting.Channels.RemoteConnection.CreateNewSocket()
at System.Runtime.Remoting.Channels.SocketCache.GetSocket(String machinePortAndSid, Boolean openNew)
at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.SendRequestWithRetry(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream)
at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream)
at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
...
=============================================================================
Where do I start in determining what's wrong with the setup, or is this just something I'll have to do differently if the app is going to straddle 2 domains?
-- modified at 1:00 Monday 26th March, 2007
|
|
|
|
|
Hi!
You could try using a http channel instead of a tcp channel...
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
I'll give that a go.
I thought I should add the client and server remoting configuration as well:
server:
<channel ref="tcp" port="6792" displayName="TCC Channel (MyServer)" authenticationMode="IdentifyCallers" secure="true" authorizedGroup="Users">
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full"/>
</serverProviders>
</channel>
client:
<channel ref="tcp" port="0" displayName="TCP Channel (MyClient)" authenticationMode="IdentifyCallers" secure="true" authorizedGroup="Users">
<serverProviders>
<formatter ref="binary" typeFilterLevel="Full"/>
</serverProviders>
</channel>
Edit: Damn HTML parsing!
|
|
|
|
|
Hi All,
My problem is:how to get files/folder names of ftp server in C#. If any one know Plz reply.
Regards
SMK
|
|
|
|
|
Hello everyone,
I am trying to add the Speech Recognission into my Windows Application. I have added a button which activates the Speech Recognission once it is clicked by assigning two Event Handeler shown bellow:
// Get an insance of RecoContext "Using Shared RecoContext".
objRecoContext = new SpeechLib.SpSharedRecoContext();
// Assign an eventhandler for the Hypothesis Event.
objRecoContext.Hypothesis += new _ISpeechRecoContextEvents_HypothesisEventHandler(Hypo_Event);
// Assign an eventhandler for the Recognition Event.
objRecoContext.Recognition += new _ISpeechRecoContextEvents_RecognitionEventHandler(Reco_Event);
Now I would like to add a button to Disable the Speech Recognission. Can someone be kind enough to tell me how I can do this? I tried the following code in order to release the event handler but it is not doing it.
//code to realease the event handler
objRecoContext = null;
Thank you so much for your help and have a great day.
Khoramdin
|
|
|
|
|
I thought you could use -= to remove an event handler ?
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 )
|
|
|
|
|
Hello Christian,
You were correct. I tried it with " -= " and it worked. I must have been on a different planet, mate.
Thank you so much for your help.
Khoramdin
|
|
|
|
|
Salam Aghayeh khorramdin!
May you explian which function do you use in order to define speech?
May I know your email?
|
|
|
|
|
Hi All,
I need to write some GUI application in MFC that will be able to support some COM call from other application.
I want to do it in C# beside MFC - but i don't know how can i write in C# and support all logical architecture that i have in COM.
How can i register the application ?
How can i define some call from other application ?
Thanks for any help.
|
|
|
|
|
You want to write a C# COM object ? There's a wizard for that, I thought.
Being COM, it will work like any COM app, I'd have thought. Otherwise, it wouldn't be COM.
Your other option is to use C++/CLI to call C# libraries within your MFC app.
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 )
|
|
|
|
|
What do you mean in there is a wizard for it ? how i getting to this wizard ?
|
|
|
|
|
Dear All,
If have the following question. I have two forms. On form one I open another form with the following code :
Form f = new Form();<br />
f.ShowDialog();
A new instance of that Form opens. However .. in form B I want to run a method from Form A. I have to reference an object.
FormA a = new FormA<br />
a.Method();
This works fine, however it opens a new instance of FormA and run the method in the new instance, while what I really want it to do is go back to the previous FormA ( already open ) and run the Method on that form.
Any suggestions ?
thx !!
|
|
|
|
|
Call the method before you do the ShowDialog
Form f = new Form();
f.Method();
f.ShowDialog();
Hope that helps.
Ben
|
|
|
|
|
Rick van Woudenberg wrote: however it opens a new instance of FormA
Yes, of course.
You can do two things.
1 - pass the instance of Form1 in to Form2 ( hack )
2 - define a delegate between the two forms, so that calling a method in form2, runs code in Form1.
There are tutorials on how to use delegates on code project.
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 )
|
|
|
|
|
FormA a;
...
...
private void call_Method_On_Form_A()
{
if(a == null)
a = new FormA;
a.Method();
}
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
I use modified Rockford Lhotka excellent SetPropertyValue()
from DataMapper class to load objects from database.
My entity object property names are mixed case.
DataReader returns lower-case only column names.
So SetPropertyValue() cannot map columns to property names.
How to change this code so that it does not depend on the propertyName case ?
public static void SetPropertyValue(
object target, string propertyName, object value)
{
PropertyInfo propertyInfo =
target.GetType().GetProperty(propertyName);
if (value == null)
propertyInfo.SetValue(target, value, null);
else
{
Type pType =
Utilities.GetPropertyType(propertyInfo.PropertyType);
Type vType =
Utilities.GetPropertyType(value.GetType());
if (pType.Equals(vType))
{
propertyInfo.SetValue(target, value, null);
}
else
{
if (pType.Equals(typeof(Guid)))
propertyInfo.SetValue(
target, new Guid(value.ToString()), null);
else if (pType.IsEnum && vType.Equals(typeof(string)))
propertyInfo.SetValue(target, Enum.Parse(pType, value.ToString()), null);
else if (pType.IsEnum && vType.Equals(typeof(decimal)))
propertyInfo.SetValue(target,
Enum.Parse(pType, value.ToString()), null);
else
propertyInfo.SetValue(
target, Convert.ChangeType(value, pType), null);
}
}
}
}
}
Andrus
|
|
|
|
|
You could try to every where you see a ToString() add a .ToLower()
to set the property name to all lower.
The method you posted seems to be where the property value is getting set. I am not sure you can make changes to where the value is getting set to get the property name to make lower case.
Hope that helps.
Ben
|
|
|
|