|
MKDIR [path] will create a directory with the specified path.
"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
|
|
|
|
|
How can I remove a method from System.Collections.CollectionBase?
Say, I have a class:
public class MyList : System.Collections.CollectionBase{}
I have all the members of the collection base such as Add(object), Remove(object), RemoveAt(index), etc...
I want to get rid of RemoveAt() and Insert() methods..
Do you have a solution?
Thanks in advance..
Radgar
|
|
|
|
|
You can't remove methods that you inherit.
You can override them with methods that throws InvalidOperationException, or you can encapsulate the collection in a class that only exposes the methods that you want.
---
Year happy = new Year(2007);
|
|
|
|
|
You have a couple of options:
1. Do not derive from CollectionBase and instead implement ICollection and/or IList directly. This will allow you to either not include undesirable insertion/removal methods or, where those methods are required by the collection interfaces, to throw a NotImplementedException.
2. Derive from CollectionBase but override the protected OnInsert() and OnRemove() methods and throw a NotImplementedException. (You have to be careful with OnInsert(), though, as that will also get called for Add(), which you *do* want to allow.)
-Phil
|
|
|
|
|
Thank you for your responses.
Radgar
"Imagination is more important than knowledge." - Albert Einstein
|
|
|
|
|
My problem is in this line of code: strResponse = wcDownload.OpenRead(UpdateUrl);
the variable strResponse receives a null value, and blows up.
I know I am going to need to figure out how to handle this exception, I know the url i am trying to access works because earlier in the code i check the modified date with today's date and it calls this method.
Here is my download method
private void Download()
{
using (WebClient wcDownload = new WebClient())
{
try
{
// Create a request to the file we are downloading
webRequest = (HttpWebRequest)WebRequest.Create(UpdateUrl);
// Set default authentication for retrieving the file
webRequest.Credentials = CredentialCache.DefaultCredentials;
// Retrieve the response from the server
webResponse = (HttpWebResponse)webRequest.GetResponse();
// Ask the server for the file size and store it
Int64 fileSize = webResponse.ContentLength;
// Open the URL for download
strResponse = wcDownload.OpenRead(UpdateUrl);
// Create a new file stream where we will be saving the data (local drive)
strLocal = new FileStream(FilePath, FileMode.Create, FileAccess.Write, FileShare.None);
// It will store the current number of bytes we retrieved from the server
int bytesSize = 0;
// A buffer for storing and writing the data retrieved from the server
byte[] downBuffer = new byte[2048];
// Loop through the buffer until the buffer is empty
while ((bytesSize = strResponse.Read(downBuffer, 0, downBuffer.Length)) > 0)
{
// Write the data from the buffer to the local hard drive
strLocal.Write(downBuffer, 0, bytesSize);
// Invoke the method that updates the form's label and progress bar
this.Invoke(new UpdateProgessCallback(this.UpdateProgress), new object[] { strLocal.Length, fileSize });
}
}
finally
{
// When the above code has ended, close the streams
strResponse.Close();
strLocal.Close();
UpdateFlag = false;
}
}
|
|
|
|
|
Hi Guys,
There is a requirement of handling the os events like logging off and mouse scroll events with the c# .Is there any way out?
saurabh walia
|
|
|
|
|
I have no idea what you mean. Do you want to write a windows hook so you capture events outside your program ?
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Is it compulsary to have a abstract method in abstract class?
Ravi
|
|
|
|
|
hi,
Good Morning,
it is not compulsory to have abstract method in abstract Class;
check with this example and give reply
public abstract class TestClass
{
public void display()
{
System.Console.WriteLine("Hello World");
System.Console.Read();
}
}
class SampleTest: TestClass
{
public static void Main(string[] args)
{
//TestClass t1 = new TestClass();
SampleTest s = new SampleTest();
s.display();
}
}
WIINING IS NOT OUR DREAM,IT'S A HABIT
HAVE A NICE DAY
|
|
|
|
|
Thanks its working without an abstract method
|
|
|
|
|
hi All,
I want to known when we go for Abstract and Interface concepts,
What are the features of Interfaces,
How it is differ from ABstract.
Pls give clarification.
Have a nice day
|
|
|
|
|
Dronala,
Abstract classes can have definitions for some of the methods while interface will never have a definition for any method. By default all members in interface are public and you can not modify it. In abstract class this is not the case. You can have any type of access modifier. You can use abstract class where you would like to provide definition for some method in base class itself and those should not be changed by its Childs. You can use interfaces if you want to implement more than one interface and give flexibility to the implementer to decide the behavior of all methods.
Jayant D. Kulkarni
Brainbench Certified Software Engineer in C#, ASP.NET, .NET Framework and ADO.NET
|
|
|
|
|
I think this is going to be a hard one...I am using C#
I have this in each of my control's MouseDown and MouseMove events:
Private int Ox , Oy ;
Private Sub BackDiag_MouseDown(object sender, MouseEventArgs e)
{
Ox = e.X;
Oy = e.Y;
}
Private Sub BackDiag_MouseMove(object sender, MouseEventArgs e)
{
ControlName.Left = ControlName.Left + (e.X - Ox);
ControlName.Top = ControlName.Top + (e.Y - Oy);
}
I can click on any control with that code and move it around at run time and it works great. Now I want to be able to select multiple controls on my form at runtime and move them in the same manner. The ideal solution would be to be able to select them as a group by drawing a square around them with the mouse (like you do when selecting multiple icons on your desktop) and also be able to add to the selection 1 at a time by holding down ctrl and clicking on them with the mouse (also like you do with icons on the desktop) and move them around as a group. That may be asking to much, so if I can't have it that way, then 1 or the other will work.
If you have any questions, please ask.
Arjun Munda
|
|
|
|
|
Hi All,
I am trying to dynamically create object based on values that being submited from a form, but keep on getting a "No parameterless constructor defined for this object." error.
<br />
Type paramType = Type.GetType("System." + Request["type"]);
String paramValue = Request["val"];
<br />
if (paramType != null)<br />
{<br />
Activator.CreateInstance(paramType);<br />
}<br />
|
|
|
|
|
What are the types that you are trying to create, and do they all have public, parameterless constructors?
-Phil
|
|
|
|
|
Hi Phil,
Right now I am just trying to create strings and ints, but will have to create other types of objects. All will be public but some will be parameterless constructors some will not.
Thanks,
tom
|
|
|
|
|
The System.String type does not have a parameterless constructor (they all require at least one parameter), and therefore cannot be instantiated via the Activator.CreateInstance(Type) method.
-Phil
|
|
|
|
|
thanks Phil,
Would you mind showing me a quick example of how to create a string via reflection. This is what I tried using before but it allways returns null.
<br />
Type[] ArgTypes = new Type[1] {Type.GetType("System.String") };<br />
ConstructorInfo oConstructorInfo = paramType.GetConstructor(ArgTypes );<br />
thanks
|
|
|
|
|
Here's one way to create the string "a" via reflection:
<br />
Type type = Type.GetType("System.String");<br />
<br />
object obj = Activator.CreateInstance(type, 'a', 1);<br />
In this case, the .NET runtime would use the System.String.String(char, int) constructor in order to create the instance because we passed a character and an integer to Activator.CreateInstance().
In the case of the .NET native types like strings and integers, however, if you already know what the value of the object will be, using reflection is overkill. There are far easier ways to translate between one native type and another.
-Phil
|
|
|
|
|
You could Create a class called MyString
add a parameterless constructor and an implicit cast
public static implicit operator string (MyString A)
{
return A._internalStringVariable;
}
public static implicit operator MyString (String S)
{
return new MyString(S);
}
Then you'll have an object that behaves a bit like a string but has a parameterless constructor.
HTH
Russ
|
|
|
|
|
Hi,
As part of the application I am working on, I would like to allow the application to dial up to the closest regional office. Our company has servers in every major city in the US so basically the only thing that I need to change is the phone number of the dial-up connection that the application is using.
I have managed to connect/disconnect using an unmanaged c++ code that is based on WinINet(InternetDial, dll or using RASDial. The problem with RasDial is that it's not reliable (At least from my experience...) and the problem with the c++ function that I am using is that it doesn't let me specify the phone number...
At this point, the only option that might be viable is to use RasDialDlg. Has anyone ever tried to use this function with c#? If yes, do you have any code samples or tips you can share with me?
Regards,
Joe
|
|
|
|
|
Hi,
I am trying to develop a webservice which will scan a given directory on the server and expose the result. I want to call this webservice from a WinForm application to populate a treeview.
Do you have any suggestions on the way I should do that ?
Thanks,
Guillaume
|
|
|
|
|
Hi,
Not sure what part you need help with, but the easiest way to consume a webserivice is build a proxy class in vs.net. Just right click on the name of your project in the soloutions explorer and the select add webreference. Then enter the url to the WSDL of your webservice and click on the add web reference button. You can then call the methods of your webservice by doiing th following.
webreferenceNameyoucreatedabove.methodName();
Regards,
tom
|
|
|
|
|
Hello all,
Hopefully someone can help me solve this problem. I'm trying to print a PrintDocument, but I get inconsistent results. Sometimes it works, and sometimes I get "The handle is invalid" or "Incorrect parameter" exceptions. I stripped it down to the following code:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Printing;
namespace PrintTest
{
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
PrintDocument pd = new PrintDocument();
PageSetupDialog psd = new PageSetupDialog();
psd.Document = pd;
if (psd.ShowDialog() == DialogResult.OK)
{
PrintPreviewDialog ppd = new PrintPreviewDialog();
ppd.Document = pd;
try
{
ppd.ShowDialog();
}
catch (Exception e)
{
MessageBox.Show(e.Message, "Exception");
ppd.Close();
}
}
}
}
}
Thanks in advance!
|
|
|
|