|
What out for strings. If you want to be really robust you will have to make a class that can take implicitly convert from doubles and ints instead of convertible.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Nice guy !
At the moment, basic numeric types as int, double, char .... are ok.
Currently I dont need any strings.
I whish you a nice day !
From which country are you coming? I'm living in Germany
|
|
|
|
|
Sorry dear guru.
Midnight has passed here and I have my next problem.
May be I get some help before I go to bed soon
class XYZ {
void fct_1<T>(T x) where T : IConvertible {
double y = x.ToDouble(null);
}
void fct_2<T>(T x, T y) where T : IComparable {
if ( x < y ) {
// some action here
}
}
}
Function fct_1() works well now (thanks for your help)
But function fct_2 makes trouble now
The compiler says now: "operand '<' cannot be applied to operands of type 'T'"
Even if I restriected to 'Icomparable'
Do you have any hints for me?
Thanks in advance
|
|
|
|
|
I think the following should work:
void fct_2<T>(T x, T y) where T : IComparable
{
if (x.CompareTo(y) < 0)
{
}
}
"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
|
|
|
|
|
I'm voiceless.
this also works
I think you joined the microsoft generic development party )
Again: Thank you very very much.
Now I will go to bed
|
|
|
|
|
My pleasure!
Have a good night
"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
|
|
|
|
|
Hello,
I am using remoting in my C# 2005 server-client implementation.
In my server channel sink implementation (in ProcessMessage()), I need to (selectively) make sure that the call to "requestMsg.Properties["__MethodName"]" method is not carried out on the server.
Ideally, I want the server to remain oblivious that the client has even attempted to call that method, yet for the called method to return "false" on the client side (if at all possible).
So far all of my attempts resulted in exceptions thrown on the client side... Any suggestions, please?
Thank you,
Victoria
|
|
|
|
|
Is it possible to use a variable to update the properties of a button? For example I have a button on my app named One is the following possible if so how do I accomplish this?
string Button = "One";
Button.Visible = true
|
|
|
|
|
I can't get the issue.can you be more specific ?
if Button is a string it does not have a Visible property and if it's a button then Button="One"; is not valid.
|
|
|
|
|
Exactly, I want to be able to assign the name of my button to a variable and then use the varible instead of the button name to adjust the button properties. I do not know if it is possible, honestly I don't believe it is but I just wanted to check here before I gave up on it.
|
|
|
|
|
You can do it using reflection.(but if you can do something explicitly , Reflection is not a good alternative)
<br />
using System.Relflection;<br />
.<br />
.<br />
.<br />
Button button=new Button();<br />
string buttonKey="button";<br />
.<br />
.<br />
.<br />
<br />
PropertyInfo visibleProp=this.Controls[buttonKey].GetType().GetProperty("Visible");<br />
visibleProp.SetValue(this.Contorls[buttonKey],true);<br />
|
|
|
|
|
You already have a variable associated with your Control/Button. The designer will do this for you.
Just look for the name in the designer.
You can then use it like any normal variable:
<br />
mybutton.Text = "Something";<br />
mybutton.Visible = false;<br />
<code><br />
<br />
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I have a DLL that was created with VB.NET and works just great with VB.NET
Windows apps. When I try to use the same DLL in a C# Windows app problems occur.
I have a simple C# Windows form test application and have added a reference to the DLL in question.
As soon as I create an instance of the DLL the form looses focus and when I close the form the program remains running and has to be ended from Task Manager.
Does any one have a clue as to what is going on here?
Jim Onwiler
|
|
|
|
|
Are you using any kind of unmanaged code in your VB.Net app.
(any API call or COM components ?)
Is there any kind of loop in your vb.net dll?
Any hardware resources is needed?
Can you debug your program?
|
|
|
|
|
There are COM components.
I ave not tried to run debug.
|
|
|
|
|
Got it!
I had a thread that needed to be aborted in the Dispose method of the VB.Net code.
Thanks for pointing me in the right direction!
|
|
|
|
|
I have an application (c#) that runs on a Windows 2000 Terminal Server.
I have various popup screens that can be closed by pressing CTL + ENTER.
These don't work on the terminal server, but they do work on any standalone computer. Any thoughts?
Paul Brower
|
|
|
|
|
You need to configure your Terminal Services Client. If you are using Remote Desktop (mstsc.exe) in XP, Setup new connection to your TS, then go to Local Resources Tab -> Keyboard section and pick "On Remote Computer" for Apply Windows Key Combinations option.
|
|
|
|
|
I did not get any answers the last time, so I thought that I would try again.
I need to do an automated form based post where I will post to another .aspx page over a secure https url. In the form post will be 9 fields of data that are text and one which is a binary file.
A NameValueCollection works like a charm for just the text input fields, but I can not seem to include the file which needs to be a binary format. The NameValueCollection expects a string value for the key pairs. I have examined what .Net provides as far as UploadData, UploadFile and UploadValues. I am using UploadValues because of the NameValueCollection.
Any suggestions on how to post everything at one time? Thanks in advance.
My code is:
int FileLen = this.Filepath.PostedFile.ContentLength;
byte[] FileBinaryData = new byte[FileLen];
HttpPostedFile theFile = this.Filepath.PostedFile;
theFile.InputStream.Read(FileBinaryData, 0,FileLen);
NameValueCollection theCollection = new NameValueCollection();
theCollection.Add("ID", "someid"); -- these values will all be suppiled.
theCollection.Add("PWORD","somepwd");
theCollection.Add("PID", "sometextvalue");
theCollection.Add("FOLDER", "sometextvalue");
theCollection.Add("FILE001", theFile); --this needs to be the binary value
theCollection.Add("TYPE1","sometextvalue");
theCollection.Add("FILE002", "");
theCollection.Add("TYPE2","");
theCollection.Add("INVOICE_NUM", "");
theCollection.Add("TOTAL_FEE","");
string url = ConfigurationSettings.AppSettings["PostingURL"].ToString();
WebClient theRequest = new WebClient();
System.Net.NetworkCredential thecred = new NetworkCredential(ConfigurationSettings.AppSettings["NTLogin"].ToString(), ConfigurationSettings.AppSettings["NTPassword"].ToString(), ConfigurationSettings.AppSettings["Domain"].ToString());
theRequest.Credentials = thecred;
byte[] responseArray = theRequest.UploadValues(url,"POST",theCollection);
string m_ResultText = Encoding.ASCII.GetString(responseArray);
return m_ResultText;
I have also tried this code since then as well, which I actually found on this site, but still no success:
public string PostFile()
{
CookieContainer cookies = new CookieContainer();
//add or use cookies
NameValueCollection theCollection = new NameValueCollection();
theCollection["ID"]= ConfigurationSettings.AppSettings["Login"];
theCollection["PASSWORD"]= ConfigurationSettings.AppSettings["Password"];
theCollection["PID"]="IMB";
theCollection["FLD"]="FF-060727-0047-1";
theCollection["TYPE"]="APSL";
theCollection["FILE2"]=string.Empty;
theCollection["TYPE2"]=string.Empty;
theCollection["INV_NUM"]=string.Empty;
theCollection["TOT_FEE"]=string.Empty;
string uploadfile;// set to file to upload
uploadfile = @"c:\\AppraisalPort\\MockProduct.pdf";
string outdata = UploadFileEx(uploadfile,"File001","application/pdf",theCollection,cookies);
return outdata;
}
public static string UploadFileEx( string uploadfile, string fileFormName,string contenttype,NameValueCollection theCollection, CookieContainer cookies)
{
string url = ConfigurationSettings.AppSettings["ProductPostingURL"];
if( (fileFormName== null) ||(fileFormName.Length ==0))
{
fileFormName = "file";
}
if( (contenttype== null) || (contenttype.Length ==0))
{
contenttype = "application/octet-stream";
}
string postdata;
postdata = "?";
if (theCollection!=null)
{
foreach(string key in theCollection.Keys)
{
postdata+= key +"=" + theCollection.Get(key)+"&";
}
}
Uri uri = new Uri(url+postdata);
string boundary = "----------" + DateTime.Now.Ticks.ToString("x");
HttpWebRequest webrequest = (HttpWebRequest)WebRequest.Create(uri);
webrequest.CookieContainer = cookies;
webrequest.ContentType = "multipart/form-data; boundary=" + boundary;
webrequest.Method = "POST";
NetworkCredential thecred = new NetworkCredential(ConfigurationSettings.AppSettings["NTLogin"],ConfigurationSettings.AppSettings["NTPassword"], ConfigurationSettings.AppSettings["Domain"].ToString());
webrequest.Credentials = thecred;
StringBuilder sb = new StringBuilder();
sb.Append("--");
sb.Append(boundary);
sb.Append("\r\n");
sb.Append("Content-Disposition: form-data; name=\"");
sb.Append(fileFormName);
sb.Append("\"; filename=\"");
sb.Append(Path.GetFileName(uploadfile));
sb.Append("\"");
sb.Append("\r\n");
sb.Append("Content-Type: ");
sb.Append(contenttype);
sb.Append("\r\n");
sb.Append("\r\n");
string postHeader = sb.ToString();
byte[] postHeaderBytes = Encoding.UTF8.GetBytes(postHeader);
byte[] boundaryBytes = Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");
FileStream fileStream = new FileStream(uploadfile,
FileMode.Open, FileAccess.Read);
long length = postHeaderBytes.Length + fileStream.Length +
boundaryBytes.Length;
webrequest.ContentLength = length;
Stream requestStream = webrequest.GetRequestStream();
requestStream.Write(postHeaderBytes, 0, postHeaderBytes.Length);
byte[] buffer = new Byte[checked((uint)Math.Min(4096, (int) fileStream.Length))];
int bytesRead = 0;
while ( (bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0 )
requestStream.Write(buffer, 0, bytesRead);
requestStream.Write(boundaryBytes, 0, boundaryBytes.Length);
WebResponse responce = webrequest.GetResponse();
Stream s = responce.GetResponseStream();
StreamReader sr = new StreamReader(s);
return sr.ReadToEnd();
}
GG
|
|
|
|
|
Green Goblin wrote: I have also tried this code since then as well, which I actually found on this site, but still no success
What do you mean by "no success"? Symptoms? Error messages?
---
b { font-weight: normal; }
|
|
|
|
|
I'm building an app that automates outlook, and I'd like it to dynamically create signitures (based on the mail recipient and the current news feeds that are around at the time).
Any ideas?
|
|
|
|
|
i want to make WinApp that will help user to write name & job
and send this to MS word File as parameter and Print it ...
ex:
see this MSWord file http://www.shoppinp.com/ADSL123.doc[^]
i want to send fname , M , lname , job as parameter this parameter will go to [Parameter1] ,[Parameter2] ,[Parameter3] ,[Parameter4]
and then print this MS Word file
............................
Palestine
|
|
|
|
|
Just use COM interop to communicate with Word.
Add a reference to the Word object library and you can use the classes contained there.
Then you can perform a search&replace, fill in text marks, whatever you like...
Regards,
mav
--
Black holes are the places where god divided by 0...
|
|
|
|
|
how can do this ???
Palestine
|
|
|
|
|
Hopefully, my last battle with Generics.
i have a class like so
<br />
public class ForumList<T> : IEnumerable {<br />
<br />
public void CreateMe()<br />
{<br />
T myclass = new T();<br />
}<br />
<br />
Is it possible to create an instance of the class or do I need to go through Reflection to do that?
Thankis,
Nick
--------------------------------------------------------
1 line of code equals many bugs. So don't write any!!
My mad coder blog
|
|
|
|