|
I'm having a problem creating a new image based on a filepath that resides on a shared server.
Basically, I'm creating a copy of an image that's located on one of our shared servers by using the following lines of code:
---------------------------------------------------------------------
String imageURL = "\\serverName\directory1\subDirectory1\subDirectory2\images\imageName.tif";
System.Drawing.Image currentImg = System.Drawing.Image.FromFile(imageURL);
---------------------------------------------------------------------
However, I get the following error on line 2:
System.IO.FileNotFoundException: \\serverName\directory1\subDirectory1\subDirectory2\images\imageName.tif
I'm doing this in the 1.1 framework. The strange part however is that this worked fine in the 2.0 framework. Now that I'm using 1.1 though, I can't get past this issue.
Any ideas as to why it can't find this filePath and what can be done to correct it?
Thanks.
-Goalie35
|
|
|
|
|
Hm...only thing I can think is that perhaps the .NET 1.1 security settings are set to less than full trust, causing network share access to be limited.
|
|
|
|
|
Hi Judah.
Thanks for the reply but that didn't seem to work.
I checked my security settings for 1.1 and all settings were set to their default levels. Just to test this out however, I set all settings to "Full Trust" and then tried running my app but still had no luck.
Like I said, it's just strange because 2.0 reads this filepath with no problem. Only 1.1 is giving me this headache.
Thanks again.
-Goalie35
|
|
|
|
|
I just noticed that your codesnippet uses "\\server..." as url without any '@' before the string initialization. Wouldn't that result in only one '\' in the actual string? As it being an escape char that is.
Just a thought.
-Larantz-
for those about to code, we salute you
|
|
|
|
|
I have a program that acts as a loader for another program and displays a splash screen while the other program is loading (it's slow). I was using the Process.WaitForInputIdle() method to wait for the other program to finish loading and it works fine...except...on one persons computer it seems to hang (I'm assuming that must be where it's hanging) and won't quit. It worked on every other computer I tried and on the one computer that hangs it seems like the program being started is running normally. Does anybody have any idea why this might happen?
In the meantime, I'm going to try the Process.WaitForInputIdle(int32) method that lets me specify a timeout.
|
|
|
|
|
I tried using WaitForInputIdle with a timeout and it doesn't seem to help. It still hangs (without any error messages). Any ideas?
|
|
|
|
|
If the problem only occurs on the one machine, then its probably the machine thats causing the problem, try re-installing .net on it or somehting, other than that, i have no idea
|
|
|
|
|
Are you certain it's hanging on WaitForInputIdle?
|
|
|
|
|
How to gate the values of some properties in the class
Like I have a Class ... Class1 in which some properties are defined say FName, LName..
Now what I have to recieve is the values that are stores in these Properties and then write them in comma separated form in a text file
How can I do this?
Parag Gupta
|
|
|
|
|
define these variables as
public static string FName;
inside the class, outside any functions.
Then you should be able to just get the value from anywhere by going:
Class1.FName
Im not sure if this is a good way of doing it or whatever, but i do it all the time, and i've never had any problems
|
|
|
|
|
If you want to use reflection (as by your title) then
object value = instanceOfClass.GetType().GetProperty("FName").GetValue(instanceOfClass, null);
That doesn't do anything different than
object value = instanceOfClass.FName;
However if you want a generic routine for saving all properties then you can do something like the following:
foreach (PropertyInfo pi in instanceOfClass.GetType().GetProperties())
{
object value = pi.GetValue(instanceOfClass, null);
}
|
|
|
|
|
Sorry, but that is not what exactly I want
What I want is that I want to apply this thing to many classes of which I don't know the properties that it contains as in....
in class1 it may be FName or LName
but what is in class 2 I don't know
I want to have some common code that will apply for all the classes I want.
the problem with this one is that here I have to call the values of all the properties individually
Please reply.
Thanks in Advance
|
|
|
|
|
Simple sample method:
public void SaveObject(object value)
{
PropertyInfo[] properties = value.GetType().GetProperties();
foreach (PropertyInfo property in properties)
{
SaveValue(propertyInfo.GetValue(value, null));
}
} Now you just call SaveObject with whatever object you want to save. Note that SaveValue will have to inspect the object to see whether it's a primitive type or a complex (e.g. TextBox ) and decide how to save it. There is a property named IsPrimitive on the Type object I think which you can use to decide what to. do.
|
|
|
|
|
'cos when I do, the type returned is:
<pre>
? _sIte_ScheduledLength.GetType()
{Name = "Int32" FullName = "System.Int32"}
[System.RuntimeType]: {Name = "Int32" FullName = "System.Int32"}
base {System.Reflection.MemberInfo}: {Name = "Int32" FullName = "System.Int32"}
Assembly: {mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089}
AssemblyQualifiedName: "System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
Attributes: Public | SequentialLayout | Sealed | Serializable | BeforeFieldInit
BaseType: {Name = "ValueType" FullName = "System.ValueType"}
ContainsGenericParameters: false
DeclaringMethod: '_sIte_ScheduledLength.GetType().DeclaringMethod' threw an exception of type 'System.InvalidOperationException'
DeclaringType: null
FullName: "System.Int32"
GenericParameterAttributes: '_sIte_ScheduledLength.GetType().GenericParameterAttributes' threw an exception of type 'System.InvalidOperationException'
GenericParameterPosition: '_sIte_ScheduledLength.GetType().GenericParameterPosition' threw an exception of type 'System.InvalidOperationException'
GUID: {a310fadd-7c33-377c-9d6b-599b0317d7f2}
HasElementType: false
IsAbstract: false
IsAnsiClass: true
IsArray: false
IsAutoClass: false
IsAutoLayout: false
IsByRef: false
IsClass: false
IsCOMObject: false
IsContextful: false
IsEnum: false
IsExplicitLayout: false
IsGenericParameter: false
IsGenericType: false
IsGenericTypeDefinition: false
IsImport: false
IsInterface: false
IsLayoutSequential: true
IsMarshalByRef: false
IsNested: false
IsNestedAssembly: false
IsNestedFamANDAssem: false
IsNestedFamily: false
IsNestedFamORAssem: false
IsNestedPrivate: false
IsNestedPublic: false
IsNotPublic: false
IsPointer: false
IsPrimitive: true
IsPublic: true
IsSealed: true
IsSerializable: true
IsSpecialName: false
IsUnicodeClass: false
IsValueType: true
IsVisible: true
MemberType: TypeInfo
Module: {CommonLanguageRuntimeLibrary}
Namespace: "System"
ReflectedType: null
StructLayoutAttribute: {System.Runtime.InteropServices.StructLayoutAttribute}
TypeHandle: {System.RuntimeTypeHandle}
TypeInitializer: null
UnderlyingSystemType: {Name = "Int32" FullName = "System.Int32"}
</pre>
where _sIte_ScheduledLength is defined as:
<pre>
private Nullable<int> _sIte_ScheduledLength;
</pre>
Surely this should come back as a Nullable`1[System.Int32] ?
Many thanks!
|
|
|
|
|
typeof(Nullable<int>>).ToString returns what you expect. My guess is doing a GetType on a nullable int with a value returns the type of the underlying value.
|
|
|
|
|
Correct. It does.
Thats my problem. Completely useless, I thought.
The reason why this is a problem is that we use our own serialisation code (the .NET serializer is not strong enough). So to serialise a value, eg.
_sIte_SchecduledLength=5;
Would become:
<sIte_ScheduledLength>5</sIte_ScheduledLength>
or if it was null ...
<sIte_ScheduledLength xsi:nil="true" />
I am happy enough to serialise like this, but need to know that it was a Nullable<int> when deserializing. And since I can't get the type, to produce something like:
<sIte_ScheduledLength Type="System.Int32">5</sIte_ScheduledLength>
It sort of scuppers my plan.
Thanks for your quick response. I'd be interested if anyone else has run into/solved this problem.
|
|
|
|
|
Does this help? http://msdn2.microsoft.com/en-us/library/ms366789.aspx[^]
*edit* it appears that article doesn't help much in that it doesn't describe a way to get at the type. I remember it wasn't designed this way, but there was a big enough outcry from developers that Microsoft changed it late in Whidbey release cycle. Joe Duffy commented on this here[^].
More info on this here[^]
|
|
|
|
|
Thanks for the links. Believe it or not, I have been Googling all day!
I particularly like:
"in order to invoke GetType the compiler inserts a box operation which transforms the Nullable. We considered newslotting a GetType method on Nullable such that compilers could bind directly to that. And of course it would have merely returned typeof(T?). But many people thought this was too hackish"
from the second link ... I don't care if it is hackish - it returns the truth!
|
|
|
|
|
Yep. From your perspective, you probably wish MS never implemented this customer requested design change. But I recall lots of people getting upset over the fact that this would otherwise return false:
int? i = null;
object o = i;
bool isNull = o == null;
In respect to your problem, it appears it's not possible with the C# language! I bet if you author some IL directly you can get at the real type of a nullable value type. But it appears to be impossible from C#.
|
|
|
|
|
Dear All,
Recently i have developed an c# application under 1024/800 resolution.
But now if i run this application under 800/600 resolution the forms controls does not show in its actual size.
For this now i did not show the forms controls while i runnig this application under 800/600 resolution.
Can anybody give me solutions regarding this?
Any help regarding this geatly appreciated.
Zakir
Software Programmer
|
|
|
|
|
Make use of Anchor and Dock properties of your controls, so they resize properly with your form.
"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
|
|
|
|
|
zakir-robi wrote: the forms controls does not show in its actual size.
What does that mean???
zakir-robi wrote: Can anybody give me solutions regarding this?
Use anchor properties for your controls.
|
|
|
|
|
i'm tring to make an application that has a tab control with multiple tab pages. for integrity purposes, i want a tab page to be rendered disabled as soon as the user moves tot he next. the only problem is that there is no enabled property for tab pages and the canfocus and canselect properties are read only. Please help me!
rzvme
|
|
|
|
|
You are correct in that you cannot disable a tab page, but you can either prevent a user from going back to a previous tab page or you can allow a user to go back to a previous tab page but disable all the controls on that tab page. The sample code below will disable all controls on a previous tab.
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
if (tabControl1.SelectedIndex > highestTabIndex)
{
foreach (Control c in tabControl1.TabPages[highestTabIndex].Controls)
{
PropertyInfo pi = c.GetType().GetProperty("Enabled");
if (pi != null)
pi.SetValue(c, false, null);
}
highestTabIndex = tabControl1.SelectedIndex;
}
}
The code is the event handler for the SelectedIndexChanged event of a tab control named tabControl1. It also assumes the existence of a form level variable declared as:
private int highestTabIndex = 0;
There are some limitations of the code, for instance if you start on tabPage1 and then click tabPage3 by skipping tabPage2 the code will disable only the controls on tabPage1. You would need to check the new index versus the old index to see if they only differ by one otherwise you could select the next page. So in this example when tabPage3 was selected by skipping tabPage2 you could change the selected tab to tabPage2 and then disable tabPage1.
Tom Chester
|
|
|
|
|
Hi...
I am developing a MDI application. In that application i am creating forms dynamically, 1 per PC comport.
In each comport i am adding textbox.& i want my application should display the received data on my each comport. I have added SerialPoer.DataReceived event in my application.
But i am not able to display the received data on that dynamically created forms...
I am adding some code with this...please suggest me where i am doing mistake...
****************************************************************************************************
private SerialPort comport = new SerialPort();
TextBox tb = new TextBox();
foreach (string s in SerialPort.GetPortNames())
{
this.f1 = new VHLCOutputWindow_Form();
f1.MdiParent = this;
f1.Controls.Add(tb);
}
MY DataReceived Event-:
comport.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string ReceivedData = comport.ReadExisting();
f1.Controls[0].Text = ReceivedData; //i've only 1 control added on that form(i.e. TextBox tb)
}
****************************************************************************************************
right now my PC is having only 1 port...& my form is getting created but i am not able to see the data received in that form...
Regards,
Vinay
|
|
|
|