Xint0 wrote:
Try adding an implicit conversion from Object to CustomThing.
I already thought of that, but it doesn't even compile because you can't have a user-defined conversion to or from the base class, so object is definitely out for that.:(
Xint0 wrote:
Try adding an implicit conversion from Object to CustomThing.
I already thought of that, but it doesn't even compile because you can't have a user-defined conversion to or from the base class, so object is definitely out for that.:(
I'll start my problem description off with some sample code which will probably do the best job at illustrating the problem. using System; namespace TestCustomTypePropertySetValue { public class CustomThing { public CustomThing(string input) { m_input = input; } public string Input { get { return m_input; } } private string m_input; public override string ToString() { return this.Input; } public static implicit operator CustomThing(string input) { return new CustomThing(input); } public static implicit operator string(CustomThing thing) { return thing.ToString(); } } public class ClassWithThing { public CustomThing Thing { get { return m_thing; } set { m_thing = value; } } private CustomThing m_thing = new CustomThing("default"); } class Class1 { [STAThread] static void Main(string[] args) { // set a custom thing to a string - this works CustomThing thing = "test custom thing input"; // set a string to a custom thing - this works string input = thing; // a property of type CustomThing ClassWithThing cwt = new ClassWithThing(); System.Reflection.PropertyInfo propInfo = cwt.GetType().GetProperty("Thing"); // set the property to a string value - this fails p
I solved this problem by using a FileStream instead of a StreamReader. The constructor of the FileStream allows you to set FileAccess and FileShare which avoids the access problems. The FileStream doesn't allow you to read line-by-line nicely, but I happen to have a class that I re-use often which acts like a TextReader but uses a FileStream in the background.
Ouch. In that scenario, would it be possible to read the file using WinAPI?
I'm trying to read a text file that just happens to be a log file for a service, and getting the following error. "System.IO.IOException: The process cannot access the file 'D:\SomeFolder\Logs\Funsv.log' because it is being used by another process." The exception makes it very clear what the problem is, but I can't find any options in StreamReader that allow me read-only access to a file, even when it's being used by another process. Does anyone know how this can be done? -- modified at 8:02 Friday 18th August, 2006
Thanks, this code will be very useful to me. However, I just want to point out that in my tests DateTime.UtcNow doesn't return the correct time because of the time zone caching. You can try it yourself by using a test similar to the first one I posted.
Unfortunately, I need to know the time zone at the exact moment that the code runs, and even 5 minutes late could cause issues. Anyway, while it's pretty cool, do you really think that your class is the simplest way to fix the problem when you can just call the GetSystemTime API?
I think I found a work-around, but I don't fully like it. If I call the GetSystemTime WinAPI function, it seems to always return the correct UTC time. I got some decent sample code from Anson Goldade's GotDotNet user sample to nicely encapsulate the API calls. Too bad Microsoft's framework methods don't call the API correctly.
I was recently looking for something like this and didn't find anything. If you absolutely need the abbreviation, you may have to create an array or enum listing them all and do the conversion yourself based on TimeZone.CurrentTimeZone.StandardName.
I have a C# windows service that depends on time comparisons that is encountering problems due to the time zone on the machine being changed. Unfortunately, this time zone change is outside of my control. I use the TimeZone.CurrentTimeZone.ToUniversalTime() and TimeZone.CurrentTimeZone.GetUtcOffset() methods to make sure all my times are converted and compared as UTC. The problem is that TimeZone.CurrentTimeZone is not updating when the machine's time zone has changed. You can reproduce this easily by creating a console app with the following lines of code, and manually changing your machine's time zone during the app's pause. Console.WriteLine("Current time zone is {0}.", TimeZone.CurrentTimeZone.StandardName); Console.Write("Waiting for time zone change. Hit 'Enter' to continue ..."); Console.ReadLine(); // manually change time zone here before app continues Console.WriteLine("Current time zone is {0}.", TimeZone.CurrentTimeZone.StandardName);
Does anyone have any idea about how to refresh or update the TimeZone.CurrentTimeZone? Thanks!
Unfortunately, I get the same error. I'm using Office 2000 and I suspect that it might be a problem with this version of office. I had a co-worker with the same PC configuration run this app and he got the same error. I'm leaving for two weeks of vacation tomorrow, so I'll have to put this issue on hold until I'm back. Thanks for your help!
I'm trying to get office automation working, and most things work except working with the Find object. For some reason, every time I try to access the Find object (both through Selection or Range) I find that the Find object is a null reference. If I try to add a watch to my Document and debug, when I expand the Selection then the Find object, my debugger crashes. I am running Office 2000. Trying similar code in VB.NET yields similar results. The following is a simple Console app that I created to test this. It only requires that the "C:\TestFindReplace\TestDoc.doc" is a valid path with a word doc that contains the text ":FULLNAME:" somewhere. Of course, you can change the filename and path to whatever if you want to test this code. Also, you will need to add a reference to the Microsoft Word 9.0 COM object. [STAThread] static void Main(string[] args) { Console.Write("Enter the person's name: "); string fullName = Console.ReadLine(); Console.WriteLine(); FindReplace(fullName); } static private void FindReplace(string fullName) { object oFileName = @"C:\TestFindReplace\TestDoc.doc"; object oNewFileName = @"C:\TestFindReplace\" + fullName + ".doc"; object oFalse = false; object oMissing = Type.Missing; object oReplaceAll = Word.WdReplace.wdReplaceAll; Word.Application WordApp = new Word.ApplicationClass(); Word.Document myDoc = WordApp.Documents.Open(ref oFileName, ref oMissing, ref oFalse, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oFalse); try { myDoc.Application.Selection.Find.Text = ":FULLNAME:"; myDoc.Application.Selection.Find.Replacement.Text = fullName; myDoc.Application.Selection.Find.Execute(ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oReplaceAll, ref oMissing, ref oMissing, ref oMissing, ref oMissing); myDoc.SaveAs(ref oNewFileName, ref oMissing, ref oMissing, ref oMissing, &nb
Greetings, fellow Columbus developer... Are you talking about VB or VB.NET? Either way, the easiest way I can think of to view a PDF file is using the Internet control, or just spawning Internet Explorer to view the PDF. As long as the client has the Acrobat Reader plug-in to IE installed, they can view the PDF.
The DataSet will load the different levels of nodes into seperate tables, but will create relationships between those tables for you. The property table that is created in the DataSet should have a relationship to the sellingpoint table, which could be accessed through the DataSet.Tables(0).ChildRelations collection. Using this DataRelation, you can access the sellingpoint children of a property row by doing DataSet.Tables(0).Rows(0).GetChildRows(DataRelation). There are other ways to do this as well. Just take a look at the help for DataSet and DataTable for more information. Or, to get an idea of exactly what is in your DataSet after loading the XML, set a breakpoint in your code, and do a QuickWatch (right click on an object after breaking into code during debug of your application) of your DataSet.
The native code compiler looks interesting, but I can't find any information about it other than the short blurb on their main page. There is no pricing or download information.
Sounds like your application should have been an ASP.NET web application since you can't control what configuration your clients would have. Of course, web applications require the client to have an internet connection (or network for intranet web servers) but that's a lot more common currently than clients with the .NET framework.
Just something like this will work: If IsNumeric(Textbox1.Text) Then ' Value entered is a number End If
I believe this will work, but I didn't actually test it against any known Epoch date values. Private Function GetEpochDate(ByVal seconds As Long) As DateTime Dim BeginningOfTime As New DateTime(1970, 1, 1) Return BeginningOfTime.AddSeconds(seconds) End Function
The following function should work for you ... Imports System.ComponentModel Imports System.Reflection Private Function GetContentTypeValue(ByVal value As Colours) As String Dim fi As FieldInfo = value.GetType.GetField(value.ToString) Dim attributes As DescriptionAttribute() = CType(fi.GetCustomAttributes(GetType(DescriptionAttribute), False), DescriptionAttribute()) If attributes.Length > 0 Then Return attributes(0).Value Else Return String.Empty End If End Function
I ran into a problem inserting/updating images through a stored procedure, I think because of a limit to the size of data sent through a stored procedure parameter. To solve this problem, I execute inserts and updates directly, like this: Public Function Insert(ByVal imageData As Byte(), ByVal imageType As String) As Integer Dim cmdText As String = "INSERT INTO MyImages(Image, ImageType) VALUES(@image, @imageType) SELECT SCOPE_IDENTITY()" Dim args(1) As SqlParameter args(0) = New SqlParameter("@image", imageData) args(1) = New SqlParameter("@imageType", imageType) Try Return CInt(SqlHelper.ExecuteScalar(ConnectionString, CommandType.Text, cmdText, args)) Catch ex As SqlException ' do error handling Throw End Try End Function
NOTE: I'm using the Microsoft Data Access Application Block[^] (SqlHelper) for data access.