|
Word, Excel is showing the preview.
But my application is not showing preview
|
|
|
|
|
Even i am also facing the same problem.Can anyone please suggest me the solution?
|
|
|
|
|
|
relative to what ?
No.
Christian Graus
No longer a Microsoft MVP, but still happy to answer your questions.
|
|
|
|
|
|
Sorry for the delayed reply but thank you very much for the useful answer.
Kind Regards,
Mushq
|
|
|
|
|
Very much a beginner C# person.
I need something simple and I'm pretty sure it can be done. I need to go to a website and simply see if a date has changed. I it has I need to pull the date back in. The date always follows the same three words so it will be easy to find.
Thanks for any who can help
dflat4now
|
|
|
|
|
Not sure I fully understand this, but it sounds like you're talking about a specific web page, and you know roughly where to find this date on the specific page. That should be easy enough--just download the content to a string via http, then "find" the date in the string (i.e. by locating the "same three words"), trim the rest away so you just have the date text, then parse this into a DateTime object using either DateTime.Parse, or another (third party) date-parsing algorithm (there are some on CodeProject) depending on the format of the date.
“Time and space can be a bitch.”
–Gushie, Quantum Leap
{o,o}.oO( Looking for a great RSS reader? Try FeedBeast! )
|)””’) Built with home-grown CodeProject components!
-”-”-
|
|
|
|
|
Use WebClient class to download the webpage content. Write a regular expresssion which finds the required date.
|
|
|
|
|
as N a v a n e e t h posted, use regular expresssion, there is software on code project named "EXPRESSo" i think it will be helpful for you to build the regular expressions.
Regards.
Tasleem Arif
|
|
|
|
|
How do I do it? I created a class called "Category" that is essentially built from some strings and an int, and i need to be able to dispose of it when i am done (there are some issues arising from "used" objects not going away)
I am inhereting the IDisposable interface, but i know that does nothing beyonf requiring you to ad a dispose method. any suggestions?
______________________
Mr Griffin, eleventy billion is not a number...
|
|
|
|
|
Vodstok wrote: I created a class called "Category" that is essentially built from some strings and an int, and i need to be able to dispose of it when i am done
There is nothing to dispose. You only need to use IDisposable if you are using unmanaged resources which you need to clean up, or you are using instances of classes that already implement IDisposable. Strings and ints fall in to neither category. The garbage collector will clean up the object when it is ready to do so.
|
|
|
|
|
ok, well that is a load off. This may be relevant to my problem: the object is being used as a static object. would that cause it to persist even though it has been "instantiated" with another identity? Essentially, the variable name is being reused on another page, but is returning all ofthe same information, even though it should be night and day different.
______________________
Mr Griffin, eleventy billion is not a number...
|
|
|
|
|
Vodstok wrote: the object is being used as a static object
Do you mean that the class is declared as static:
public static class MyClass
{
}
Vodstok wrote: would that cause it to persist even though it has been "instantiated" with another identity?
I don't understand what you mean by that. A static object, once created, will persist for the life of the application. You don't "instantiate" the object directly, the CLR decides when to do that. It is possible that a static class won't be "instantiated" (actually, for static classes, the term is "initialised") at all.
Vodstok wrote: Essentially, the variable name is being reused on another page, but is returning all ofthe same information, even though it should be night and day different.
If it is static then there is only ever the one "instance" (if you like).
|
|
|
|
|
sort of. the class isnt static, but the instance is:
public class Category
{
private static Category cat = null;
public static Category Instance(int id)
{
if(cat == null)
cat = new Category();
return cat;
}
Just an example snippet, but that is the gist of it
______________________
Mr Griffin, eleventy billion is not a number...
|
|
|
|
|
Vodstok wrote: the class isnt static, but the instance is
Okay - You are using the singleton pattern (which ultimately should produce the same effect as a static class - except you have a lot more work to do)
So, with that in mind, back to what you said earlier:
Vodstok wrote: ok, well that is a load off. This may be relevant to my problem: the object is being used as a static object. would that cause it to persist even though it has been "instantiated" with another identity? Essentially, the variable name is being reused on another page, but is returning all of the same information, even though it should be night and day different.
Assuming that the Instance method is the only thing that creates an Instance of the Category class (and that the constructor which isn't shown is private*) then it will get created once, and once only. The logic does not permit any other instance to be created.
It doesn't matter where in your application you access this, you will always get the same instance back.
* Which is normal for a singleton
|
|
|
|
|
For starters, you answered a question i have had for a long time, whihc was "what the hell is this method of creating objects called", so THANK YOU, it has been eating at me since i was introduced to it last year.
So let me see if i understand this properly. I use the method Category.Instance(1) to create an instance of an object, then go back and create Category.Instance(4), I now have 2 distinct objects that should not overlap in any way shape or form?
I may have another unrelated problem, but as long as Ikno where not to loolk, i will be better off
Again, Thank you
______________________
Mr Griffin, eleventy billion is not a number...
|
|
|
|
|
Vodstok wrote: I use the method Category.Instance(1) to create an instance of an object, then go back and create Category.Instance(4), I now have 2 distinct objects that should not overlap in any way shape or form?
No, you still only have one object. I've annotated your code below:
public static Category Instance(int id)
{
if (cat == null)
cat = new Category();
return cat;
}
The logic prevents the creation of a new instance. cat is a static field, which means there will only be one regardless of how ever many instances of the class you create.
If you want to create new distinct objects through a method you may want to look at the Factory Pattern instead - the code above is part of the Singleton Pattern. (Are you familiar with design patterns? Or have you just muddled through and stumbled upon them without realising? - Both scenarios are good in different ways).
The Factory Pattern is a design pattern that permits a method (or class) to be responsible for the creation of objects. It can be a lot more flexible than using basic constructors.
The Singleton Patterns is a design pattern that constrains a class so that there will only ever be one instance of the class. In C# this is more commonly achieved by using a static class (i.e. the pattern is built in to the language). In other languages you can do this by controlling all instantiation through a single method (this is what you are doing in your code)
|
|
|
|
|
I found out what my problem was....
i have the block that starts with if(cat == null), and all of the logic assigning values to the various strings and ints in the object were contained in that block, so when i feed it a new id, it does nothing with it, exactly the way i coded it.....
______________________
Oh Hamburgers!
|
|
|
|
|
Vodstok wrote: I found out what my problem was....
This is what happens when I start writing a reply, get distracted, come back and finish it off... You find the answer by yourself.
|
|
|
|
|
I appreciate you taking the time, and to answer the question in your other post, I have been muddling around in this pattern with no clear understanding of how it worked, but just that it made my life way easier.
I have not ever looked at desing patterns.
______________________
Oh Hamburgers!
|
|
|
|
|
Vodstok wrote: I have not ever looked at desing patterns.
You might want to look out for a book on the subject. There are books on design patterns in C#, or there are generic books that apply to any language. It would seem to me that you have figured out, or almost figured out, some on your own. Reading up on the subject will help get you a better understanding, and you can short circuit some of the trial and error of getting the thing right in the first place. It will also give you some good ideas of how to proceed in areas where perhaps you are still figuring things our, or have a solution that just does not feel right.
Once you have studied the basic patterns you can migrate on to some of the more interesting (in my opinion) patterns as given in Martin Fowler's book Patterns of Enterprise Application Architecture (IIRC). I wouldn't jump in to that book straight away though, it's a reference book for the most part, you'd need to understand the basics to get the best out of it.
Good luck.
|
|
|
|
|
Thank you again, it looks like i have some reading to do
______________________
Oh Hamburgers!
|
|
|
|
|
This is 50% curiousity, 50% because I might want to do this (so if this is a 'DON'T DO THIS EVER' type thing, by all means tell me) but I don't even know if its possible.
Say you had something like this:
class Book;
class CheckedOutBook : Book;
class Library
..void CheckOut(ref Book b, Person p);
Is it possible for CheckOut() to transform the book input into it so it is now a CheckedOutBook?
Obviously, you can return a new instance of CheckedOutBook, but I'm specifically talking about transforming the reference - my memories of C++ are that with pointers it should certainly be possible, but is it in C#?
To be clear I'm thinking of something like this:
Book b = new Book("Design Patterns");
(new Library()).CheckOut(b, new Person("Frank"));
Diagnostics.Assert(b is Book);
Diagnostics.Assert(b is CheckedOutBook);
|
|
|
|
|
Togakangaroo wrote: This is 50% curiousity, 50% because I might want to do this (so if this is a 'DON'T DO THIS EVER' type thing, by all means tell me) but I don't even know if its possible.
Code in the base class can cast itself to a derived class IF (AND ONLY IF) the object is actually an instance of the derived class in the first place.
HOWEVER, (and you're way ahead of me), this is a "DON'T DO THIS EVER" type of thing. The base class should have no knowledge of its derived classes. It is the responsibility of the derived class to know about its base.
If a base class uses information about derived classes then you lock the base class effectively. The base is no longer open to extension by other new derived classes at a later date. Any new derived class would potentially require changes in the base. This is bad.
Togakangaroo wrote: Is it possible for CheckOut() to transform the book input into it so it is now a CheckedOutBook?
This is a different question. CheckOut is a method on Library which is not in the same class heirarchy as Book and CheckedOutBook .
You have a ref Book b in the method signature, so I suppose you could REPLACE b with a CheckedOutBook but not transform the existing one. Also I consider using ref and out to be poor practice. In an OO system there are many better ways to accomplish the same thing. I see that there is no return value for the method so there really is no reason at all to be using ref as you can do that through the return value.
Also, the implication of CheckedOutBook is that you are assigning state (whether the book is checked out or not) to the class. State should be a property of the class, not the reason d'etre of the class.
I hope this helps.
|
|
|
|