|
You've asked this question 3 times now! (That I know of)
Google[^]
My failometer is detecting vast quantities of FAIL!
"Its SQL - hardly programming..." (Caslen)
|
|
|
|
|
Hi Fly,
Sorry, but I had to repeat my question everytime since I didnot get any appropriate or deserving response. And BTW, this ain't that easy. I know of using the foreach loop here but I need the idea, that "How to?"
Cheers,
Rajdeep.NET
|
|
|
|
|
Rajdeep.NET wrote: I had to repeat my question everytime since I didnot get any appropriate or deserving response.
Yes you did, you either could not be bothered or don't have the skill to use the answers, in which case you should buy a book or try something basic like previous people have explained.
Rajdeep.NET wrote: BTW, this ain't that easy.
Yes it is.
My failometer is detecting vast quantities of FAIL!
"Its SQL - hardly programming..." (Caslen)
|
|
|
|
|
static void Main(string[] args)
{
FindFile(@"d:\", "32bit.zip");
}
static void FindFile(string directoryName, string fileNameToFind)
{
string[] directories = Directory.GetDirectories(directoryName);
string[] files = Directory.GetFiles(directoryName);
foreach(string file in files)
{
FileInfo fileInfo = new FileInfo(file);
if(fileInfo.Name == fileNameToFind)
{
Console.WriteLine(fileInfo.FullName);
}
}
foreach(string directory in directories)
{
FindFile(directory, fileNameToFind);
}
}
|
|
|
|
|
stancrm wrote:
string[] files = Directory.GetFiles(directoryName);
foreach(string file in files)
{
FileInfo fileInfo = new FileInfo(file);
if(fileInfo.Name == fileNameToFind)
{
Console.WriteLine(fileInfo.FullName);
}
}
You can replace that with if (File.Exists(directoryName + "\\" + fileNameToFind)) . This would save you having to use the files variable which would take up space on the memory stack.
Also
stancrm wrote: FileInfo fileInfo = new FileInfo(file);
if(fileInfo.Name == fileNameToFind)
Path.GetFileName(file) would to the same thing as fileInfo.Name without having to create a new new FileInfo instance.
My failometer is detecting vast quantities of FAIL!
"Its SQL - hardly programming..." (Caslen)
|
|
|
|
|
Thanx Stancrm! That worked!
|
|
|
|
|
I honestly think you should buy a book or two to help you with these simple tasks. Maybe learn how to google as well??
Anyway, I would suggest you look at the DirectoryInfo and FileInfo classes. These have nice attributes like SearchOption.AllDirectories which you can use to do what you want to do. I was going to post you some sample code but I recon you can figure it out and post it back once you have it working.
So, go ahead and check it out and I would like to see your sample code to show us that you are atleast helping yourself and not just posting for people to write your code for you!!
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Hi Kwagga,
Actually, I am just a begineer now and my english isn't strong. I know what exactly I've to search but I dont find words to describe that while googling. Thanks for providing the attribute SearchOption.AllDirectories but I would have been very grateful to you if you provide a sample code to me.
Please help,
Rajdeep.NET
|
|
|
|
|
Hello,
I want to use HttpWebRequest to login and change some settings on a website. In order to do that i need to change the URL addresse of the currenct HttpWebRequest (Login Page) to another web page (Setting Page). I googled this matter and i found out that the RequestUri and HttpWebRequest.Headers["host"] are both readonly.
So here is my question:
1. How can i change the url address of the HttpWebRequest object after creating the object.
For Example:
WebRequestObject = (HttpWebRequest)HttpWebRequest.Create("http://www.yahoo.com");
WebRequestObject.RequestUri = "http://www.google.com";
2. Is there an alternative class in c# for better http functionality?
Any kind of help would be appreciated.
|
|
|
|
|
Ehsan Baghaki wrote: Is there an alternative class in c# for better http functionality?
Response.Redirect or Server.Transfer
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
I add any zedgraphcontrol to form and i Want with chenge cursor on the right border control and drag , chenge size zedgraphcontrol? pleas help me thanks.
|
|
|
|
|
I have never heard of the zedgrapg control - but why not try putting it on a splitcontainer, docked to fill, then resizing the split container will probably just work as if by magic
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
I have a typical problem. It is like I want to execute some API calls based on the Platform, if one API is not supported by the current platform it will throw an exception. I want to implement it like this:
<br />
[Platform(Platform.Win32NT)]<br />
[DllImport("somedll.dll")]<br />
public static extern int APIcall([In] int param1, float param2);<br />
<br />
<br />
public int CallTheAPI(int param1, float param2)<br />
{<br />
return APICall(parma1, param2);
}<br />
How should I implement Platform attribute and accomplish the operation? Please give some idea.
|
|
|
|
|
try this one.
<br />
[Platform(Platform.Win32NT)]<br />
[DllImport("somedll.dll")]<br />
public static extern int APIcall([In] int param1, float param2);<br />
<br />
<br />
public int CallTheAPI(int param1, float param2)<br />
{<br />
if (!System.Environment.OSVersion.Platform.ToString().Equals("Win32NT"))<br />
{<br />
throw new ApplicationException("Your current platform is not a Win32NT operating system.");<br />
}<br />
return APICall(parma1, param2);
}<br />
<br />
<br />
|
|
|
|
|
Basically , this is ok for one or two api calls. But I am here handling with more than 300 calls. So instead of putting the if conditions everywhere , just using attribute over each api signature would be lot easier. That is why i am posting this question to get it in a easier way.
|
|
|
|
|
I guess you're looking for a generic method dispatch mechanism that validates the platform before executing calls. How about something like this.
enum Platform
{
XP,
NT,
Vista
}
class PlatformNameAttribute : Attribute
{
public PlatformNameAttribute(Platform platForm)
{
this.Platform = platForm;
}
public Platform Platform { get; set; }
}
class Program
{
[PlatformName(Platform.NT)]
static void SomeAPICall()
{
Console.WriteLine("NT");
}
[PlatformName(Platform.XP)]
static void SomeOtherAPICall(int x)
{
Console.WriteLine("XP");
}
static Platform GetCurrentPlatform() { return Platform.NT; }
static void ExecuteAPICall(Delegate d, params object[] parameters)
{
var attributes = d.Method.GetCustomAttributes(typeof(PlatformNameAttribute), false);
if (attributes != null && attributes.Count() > 0)
{
var platformAttribute = (PlatformNameAttribute)attributes[0];
if (platformAttribute.Platform != GetCurrentPlatform())
{
throw new InvalidOperationException("Platform Type mismatch");
}
d.DynamicInvoke(parameters);
}
}
static void Main(string[] args)
{
ExecuteAPICall(new Action(SomeAPICall));
ExecuteAPICall(new Action<int>(SomeOtherAPICall), 2);
}
You could do something more typesafe than DynamicInvoke, with Expression and lambdas, but that would require .NET 3.5, and I'm not sure you are running it.
|
|
|
|
|
That's a cool solution and I already tried it. But the problem is when API calls uses parameters with ref / out keyword or it has a large number of parameters say 7 or something or have parameters with marshalas attributes you can't use either Action or Func. I am not sure in that case if this method dispatcher will work or not.
For your information I am using .Net 3.5.
Any kind of suggestion is highly required.
Thanks.
|
|
|
|
|
I have the class Class1:
public enum Protocol
{
Digital,
Analog
}
public enum Model
{
Digital1,
Digital2,
Analog1,
Analog2
}
public static Protocol m_selectedProtocol;
public static Model m_ModelSelected;
public static Protocol SelectedProtocol
{
get { return Class1.m_selectedProtocol; }
set { Class1.m_selectedProtocol = value; }
}
public static Model ModelSelected
{
get { return Class1.m_m_ModelSelected ; }
set { Class1.m_ModelSelected= value; }
}
Then here is the code being executed:
if (rdAnalog.Checked == true)
{
Class1.SelectedProtocol = Protocol.Analog;
if (Analog1.Checked == true)
{
Class1.ModelSelected = Model.Analog1;
}
else if (Analog2.Checked == true)
{
Class1.ModelSelected = Model.Analog2;
}
else
{
return;
}
else
{
return;
}
i have this error when this line is executed :Class1.SelectedProtocol = Protocol.Analog;
How can it be solved ? thanks
|
|
|
|
|
The code you have presented (except of a coouple of typos) works -
public class Class1
{
public enum Protocol
{
Digital,
Analog
}
public enum Model
{
Digital1,
Digital2,
Analog1,
Analog2
}
public static Protocol m_selectedProtocol;
public static Model m_ModelSelected;
public static Protocol SelectedProtocol
{
get { return Class1.m_selectedProtocol; }
set { Class1.m_selectedProtocol = value; }
}
public static Model ModelSelected
{
get { return Class1.m_ModelSelected ; }
set { Class1.m_ModelSelected= value; }
}
}
private void button1_Click(object sender, EventArgs e)
{
Class1.SelectedProtocol = Class1.Protocol.Analog;
}
so there is something in the code you have not posted causing the problem - are you able to post some complete code that shows the problem?
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
Here is the code :
if (rdAnalog.Checked == true)
{
Class1.SelectedProtocol = Protocol.Analog;
private void buttonStartTest_Click(object sender, EventArgs e)
{
try
{
if (Analog1.Checked == true)
{
Class1.ModelSelected = Model.Analog1;
}
else if (Analog2.Checked == true)
{
Class1.ModelSelected = Model.Analog2;
}
else
{
return;
}
else
{
return;
}
}
catch (Exception c)
{
MessageBox.Show(c.Message);
Environment.Exit(0);
}
}
|
|
|
|
|
I'd need to see the code for Class1 - sorry if I wasn't clear. As someone says below, it could be a static constructor causing the issue - but without seeing the code for the class it's hard to guess.
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
It seems that you have missed a '}' in your code. Changing your code like below is working
if (rdAnalog.Checked == true)
{
Class1.SelectedProtocol = Protocol.Analog;
if (Analog1.Checked == true)
{
Class1.ModelSelected = Model.Analog1;
}
else if (Analog2.Checked == true)
{
Class1.ModelSelected = Model.Analog2;
}
else
{
return;
}
}
else
{
return;
}
|
|
|
|
|
One of the types involved probably has a static constructor, and I'm guessing that static constructor is throwing an exception.
Put breakpoints in the static constructors of all classes involved, and step through them in the debugger.
|
|
|
|
|
hello
I installed my keypair into CSP using sn.exe
sn.exe -i mykeypair.snk MYKEYPAIR_RSA_SNKContainer
Now how do I access CSP? I can't find anything under Control Panel>Administrative tools.
Thanks
dev
|
|
|
|
|
Hi,
while working with an application , i came across method signature that used 'this' keyword. I googled alot but coudn't find any article that provided help, would anybody over here please tell me or either forwrd me an article that explains this method description. thankou
public static bool IsPart(this Product product)
{
try
{
return product.isPart.Value == "true" ? true : false;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return false;
}
}
though, i have pasted the whole method but i am confused with function signature . Thanx for providing help
|
|
|
|