|
normally the DBs on a local/personal computer not Server/Network should be in a folder like:
C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA
|
|
|
|
|
Ok. Thanks
|
|
|
|
|
Hello,
I'm attempting to have a console program take a path as an argument.
I have the following code executing:
static void Main(string[] args)
{
HandleArgs(args);
}
public static void HandleArgs(string[] args)
{
foreach (string arg in args)
{
if (arg.Contains("/path:"))
{
string execpath = arg.Substring(6, arg.Length - 6);
}
}
}
What i'd like to do is to take the string[] args as it is passed to Main() as a verbatim string.
The problem arises when the argument /path: is input as /path:"c:\documents and settings\" . The string arg in args is not verbatim, and execpath is then c:\documents and settings\" not c:\documents and settings\ as desired.
Another foreseeable situation is the the /path: argument is /path:""c:\documents and settings\" , as I am attempting a condition to determine if the last character is a \
How can I take the string into string[] args passed to Main() as a a verbatim string.
Thanks,
Matt
|
|
|
|
|
I'm not sure what you're asking; the term "verbatim string" makes no sense in this context.
If you want the command line as it appears on the command line, and not split into a string array, then try System.Environment.CommandLine
P.S. If you mean that you are looking at the string in the debugger and seeing \" rather than " -- please remember that the \ is not really there, it's only displayed for your convenience -- write it to the console and see for yourself.
modified on Thursday, April 1, 2010 12:54 PM
|
|
|
|
|
The following are the command line arguments:
/path:"c:\Documents and Settings\mbrown\Desktop\securable.exe" /save:"c:\Documents and Settings\mbrown\Desktop\"
The following code:
try
{
Console.WriteLine(savepath + "~scrublbdy.tmp");
streamer = File.CreateText(savepath + "~scrublbdy.tmp");
streamer.WriteLine("All work and no play makes Jack a null toy.");
streamer.Close();
File.Delete(savepath + "~scrublbdy.tmp");
}
catch (Exception err)
{
Console.WriteLine(err);
Environment.Exit(1);
}
Produces the following error:
C:\Documents and Settings\mbrown\My Documents\Visual Studio 2008\Projects\securable_buddy\Securable_Buddy\Securable_Budd
y\bin\Release\Securable_Buddy.exe /path:"c:\Documents and Settings\mbrown\Desktop\securable.exe" /save:"c:\Documents and Settings\"
c:\Documents and Settings"\~scrublbdy.tmp
System.ArgumentException: Illegal characters in path.
at System.IO.Path.CheckInvalidPathChars(String path)
at System.IO.Path.GetFileName(String path)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileO
ptions options)
at System.IO.StreamWriter.CreateFile(String path, Boolean append)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
at System.IO.StreamWriter..ctor(String path, Boolean append)
at System.IO.File.CreateText(String path)
at Securable_Buddy.Program.HandleArgs(String[] args) in C:\Documents and Settings\mbrown\My Documents\Visual Studio 2
008\Projects\securable_buddy\Securable_Buddy\Securable_Buddy\Program.cs:line 117
Note c:\Documents and Settings"\~scrublbdy.tmp .
The trailing \ is being treated as an escape character in the argument. So the "best" solution I can think of is making the arguments that are passed to the main() function be verbatim strings.
Any idea how to modify the incoming args to the Main() function static void Main(string[] args) to make them literal?
Thanks,
Matt
|
|
|
|
|
bbranded wrote: Any idea how to modify the incoming args to the Main() function static void Main(string[] args) to make them literal?
You cannot modify them. The .NET command line parser doesn't have any options.
The only solution I see is the same as PIEBALDconsult suggested: take Environment.CommandLine and parse it yourself.
|
|
|
|
|
|
Or maybe you need a simple Trim ?
|
|
|
|
|
Ok so I have a parent form called frmMain and a child panel called panelMasterlist.
In panelMasterList I have created a delete event(right click context button) on the frmMain there is a Delete button as well
I need to trigger the same event from the frmMain as in the panelMasterlist.
In panelMasterList the clcik event is: public void contextDeleteMasterList_Click(object sender, EventArgs e)
so I was thinking in the frmMain I can send a event argument to the namespace.class? Not sure how to do this
|
|
|
|
|
To fire event you can use the MenuItem.PerformClick method.
To call it from the form you should expose a public method in the PanelMasterlist class that fire the delete event, something like this:
public void DeleteMasterList()
{
contextDeleteMasterList.PerformClick();
}
|
|
|
|
|
Create a method that handles the action and call it from both the main form menu item and the panel context menu item
private void Delete()
{
}
protected void OnDeleteMenu(object sender, EventArg e)
{
Delete();
}
protected void OnDeleteContextMenu(object sender, EventArg e)
{
Delete();
}
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi forum
I have this inconvenience
I have an application with a Grid Property, and im saving my properties to a file with XML.
So when I open the created file i see this
...
<property>
<name>Path</name>
<type>System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</type>
<value>
<string />
</value>
</property>
<property>
<name>Export_To</name>
<type>System.String[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</type>
<value />
</property>
<property>
<name>Species</name>
<type>System.Collections.Generic.List`1[[MySolution.MyProject.MyClass.Species, MyDLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</type>
<value />
</property>
</properties>
...
Until here is OK. The problem is when i want to load newly this file. The problem is because i have my class into a dll (created by me).
For this motive Im getting this error message.
"Is not possible load the file or assembly 'MyDLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'" or one of it's dependencies. The System can not find the file specified.
but if I include this property into my project 'directly' there is no problems (the problem is that i need this into my dll)
Can some body tell me how to fix this problem, to load newly my properties
Thankyou
|
|
|
|
|
If I understand correctly, you are attempting to use reflection to instantiate the "MyDll" assembly using the config data held in your Xml file. if so, are you specifying the path correctly when you load the assembly? By default the assembly trying to load MyDll will look in its own path, unless you specify an explicit location. check that MyDll.dll is located in your executing assemblies bin folder.
|
|
|
|
|
Hi
Thank you for your help...
but, i don't want to copy the dll to the assemblies bin folder, what i want is save my data (xml) in any location and later load this file without specify a path.
For example:
if my dll is into c:\tmp\mydll.dll
and i try...
<property>
<name>MyProperty</name>
<type>System.Collections.Generic.List`1[[MySolution.MyProject...MyClass.MyProperty, c:\tmp\mydll.dll, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</type>
<value />
</property>
it fails me.
How can i fix it?
Thank you
|
|
|
|
|
Hi
It would seem to me that the issue is related to the location of the myDll.dll (or at least where the calling code is expecting to load it from). Please supply a snippet of the code that in creating your myDll.dll and if possible, the full error detail you are getting.
|
|
|
|
|
Hi,
I am wondering, if I need to dispose the LINQ to SQL DataContext Object or it will be collected by the Garbase Collector ? In my ASP.NET Application, I am using many instances of DataContext Object in different method in a same page and my server complained that, I am causing memory issue. I am suspecting it could be related to my usage of LINQ to SQL DataContext, but I dont understand if I should use a single static DataContext in my Web Page so that all methods in the same page shares that DataContext Object or If I should create new instance of DataContext object in every method ? I placed the DataContext within a using statement so that it get disposed as soon as it is used, but I get an Exception 'Cannot access Disposed data context object'. So, I am getting more confused. How come the object gets Disposed already before using it ? Would you please tell me about the best way of disposing the data context in ASP.NET application so that I can optimize for memory usage ?
|
|
|
|
|
Sounds like you have tried to reference the DataContext object outside of the using construct.
Can you show a fragment of your code?
me, me, me
"The dinosaurs became extinct because they didn't have a space program. And if we become extinct because we don't have a space program, it'll serve us right!"
Larry Niven
|
|
|
|
|
Hi,
Thanks a lot for your reply. I have following code in my ASP.NET page. I am wondering If it is more efficient to place the line SpDBDataContext myDbContext = new SpDBDataContext(); globally and override the Page's Dispose method and call the myDbContext.Dispose() method inside that Disposer !!
<br />
protected void _linqDataSourceProductsFirst_Selecting(object sender, LinqDataSourceSelectEventArgs e)<br />
{<br />
using (SpDBDataContext myDbContext = new SpDBDataContext())<br />
{<br />
var productResults = myDbContext.products.Where(x => emran.publish).OrderBy(x => x.isFeatured);<br />
e.Result = productResults;<br />
}<br />
}<br />
This linqDataSourceProductsFirst is a LinQDataSource control placed in ASP.NET page.
|
|
|
|
|
I highly doubt that the DataContext is causing any memory issues, you have other issue that need to be resolved.
Emran Hussain wrote: How come the object gets Disposed already before using it ?
Your answer is here
Emran Hussain wrote: I placed the DataContext within a using statement so that it get disposed as soon as it is used
From the sounds of it you need more education on designing and implementing a layered system and how garbage collection works in the .net framework.
Your data access should be abstracted out of the page code, in a separate class or even assembly. Start there.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi Mark, thank you very much for your reply. I realized that I need to know a pattern using DataContext. I have following code in my ASP.NET page. I am wondering If it is more efficient to place the line SpDBDataContext myDbContext = new SpDBDataContext();
globally and override the Page's Dispose method and call the myDbContext.Dispose() method inside that Disposer !!
protected void _linqDataSourceProductsFirst_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
using (SpDBDataContext myDbContext = new SpDBDataContext())
{
var productResults = myDbContext.products.Where(x => emran.publish).OrderBy(x => x.isFeatured);
e.Result = productResults;
}
}
About using layered system, actually I know layered system as I used to have Data Access Layer whole life until I learned LINQ to SQL. I always hated data access layer because, if I change a table schema in my SQL server database, I had to manually find out my data acccess layer which code needs change as the application will still compile with a wrong SQL Schema. So, when I learned LINQ to SQL, I just felt great and new I feel free to change any table column in SQL server and then, drag and drop the new Table to the ORM page and then, I get error in compile time where the usage needs changing. So, to my point of view, the ORM page (.dbml page) is working as a data access layer where I place my LINQ query directly within my code. It is just for maintainance peace.
modified on Thursday, April 1, 2010 1:26 PM
|
|
|
|
|
Emran Hussain wrote: I used to have Data Access Layer whole life until I learned LINQ to SQL.
LinqToSql doesn't change anything.
Emran Hussain wrote: I always hated data access layer
Then, very bluntly, you are a fool.
Emran Hussain wrote: the ORM page (.dbml page) is working as a data access layer
Then you don't really understand layered design or how to use the tools effectively.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi Mark,
I agree with you that I need more knowledge about it. Actually so far I did not find any article that discuss any Design Pattern using LINQ to SQL. If I search for LINQ to SQL article, I find millions of links which teach about the LINQ query expressions. Anyway, thank you for your help.
|
|
|
|
|
Emran Hussain wrote: I did not find any article that discuss any Design Pattern using LINQ to SQL
Because patterns are not depended on any particular technology.
"In software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design. A design pattern is not a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations."
http://en.wikipedia.org/wiki/Design_pattern_(computer_science)[^]
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
hi, Can you please tell me how I can select all controls with ctrl+a at runtime?
|
|
|
|
|
at runtime? How it could be? you can define your own routines that draws a selection rectangle around every control when the user hits Ctrl+A.
Regards,
Mohammad Elsheimy
---------------------------
Just Like a Magic
http://JustLikeAMagic.Wordpress.com
|
|
|
|