|
I am building a custom WebControl and I would like to render an image in that custom control. I have a solution but it is not the solution I would like. Currently I am saving my image as a file and writing an html "img source" tag pointing to that file at the time I am asked to render my control into the HtmlTextWriter.
The solution I would like is to be able to stream the image into the page so that I am not required to create an image file.
Is this possible?? Thanks.
|
|
|
|
|
What I had done is:
set the "img source" to myPic.aspx
then in myPic.aspx.cs in the Page_Load event, write to the output stream:
"MIME=image/jpeg" // or something like that
and then just write your image you draw to the stream as well.
Bitmap bm;
// draw to it
bm.Save( Response ); // the response stream
this works, i have done it before, but this is not exactly correct, can't remeber the exact words/code not sure of the correct form for MIME type, but look on google for MIME types or something.
You can even pass parameters to yout myPic.aspx?lines=1,2,8,9
which could draw a line from 1,2 to 8,9
Or save the bmp in the Session and retreive it from the sesion when the client requests myPic.aspx, but i have not tried this session idea before.
Hope that might help.
|
|
|
|
|
Bob Scoverski wrote:
The solution I would like is to be able to stream the image into the page so that I am not required to create an image file.
Yes, I wrote an article on it here: Web Graphics On The Fly in ASP.NET[^]. Hope this helps.
- Nick Parker My Blog
|
|
|
|
|
Hi there,
I was wondering how I could go about writing an array of strings containing any character, into a hidden web control (textbox), and also as a parameter in a javascript function call. And not have it screw up the html on the rest of the page. Then be able to parse the one long string back into an array of strings, upon post back.
The one long string can't have single quotes in it, cause it will screw up my javascrip parameter which wraps single quotes around the string.
I would guess it would have to first write all the strings as one long one with some delimiter (that delimiter might already exist in the string and needs to be handled), and then convert that one big string into some kind of html compatible string not to screw up the rest of the html, or javascript parameter.
Would some kind of XML work for sticking all strings into one big string? And UML or URL converter class work?
Anyone have any ideas? I am hoping for some built in classes in the framework. There must be some kind of delimiter string creator class and html formatter class? I cant find any.
Thanks in advance.
Kris.
|
|
|
|
|
See the HttpUtility for an HtmlDecode and HtmlEncode method. You could encode each array element, then join then with a ','. When you need the array again, split on ',' and decode each element. Fortunately, javascript also has both an encode and decode method that you could use. Works out great.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Wow, thanks alot Heath.
You have always been the one to asnwer all my questions, and your always right
Well, thanks again.
|
|
|
|
|
Hi everyone,
I have a moule that generates some excel files over an ASP.NET page. Depending on the request, some files can take a long time to download. So, I thought it would be a nice idea to use a web service that would do this in the background.
I have no experience with web services whatsoever. Is it possible to do the following with the web service:
- The client does not get stuck in the page. Basically, the request should be processed in the background. Currently, when I do this in an ASP.NET page, the page waits on the load till the request is complete. What I want is to process the request in the background and the user should be free to browse the site.
- Have a callback that will notify the user that the request has been complete.
If someone can suggest on such background processing of tasks, I would be really grateful.
Thanks,
Pankaj
Without struggle, there is no progress
|
|
|
|
|
HTTP is a stateless protocol, allowing only one-way communications (clients make a request, server returns a response). You couldn't use a callback because the server can't alert the client. You could, however, use a session variable to signify when a particular action is done so that when the client receives the response from the server after this variable is set, you can display something to link them to the generated Excel file. You don't even need XML Web Services to implement such a feature. This isn't an easy task, though, and you should better familiarize yourself with how ASP.NET works by reading the .NET Framework SDK, specifically the topics related to ASP.NET[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'd like to experiment with an IntPtr and strings. How do i retrieve a string from an IntPtr and convert a string to an IntPtr for the purpose of marshaling?
Basicaly, I've built a version of SHGetPathFromIDList in my program and i'm converting a PIDL to the file path, however the pre created string I am marshaling to it does not get modified properly, so i would like to send a pointer to a string instead.
(There is a post about this problem in the COM forum that covers the finer details, but for now i'd just like to convert an IntPtr to a string or Vis Versa.)
Cheers
Cata
Edit: I suppose the question is - How do I construct a buffer (char array?) of size Max_Path, and then create a pointer to it?
|
|
|
|
|
See the System.Runtime.InteropServices.Marshal class. It has a lot of static methods to facilitate marshaling between things like String s and IntPtr s. For a specific method, see Marshal.PtrToStringAuto (methods exist for ANSI, BSTR, and Unicode as well when you know that a string will always be encoded a certain way, otherwise Auto is ANSI on Windows and Unicode on Windows NT.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks heath.
Just tell me, am I on the right track for handling a buffer? I take it I am constructing a space in memory that will have the file path written to it.
It's not an out, or ref call is it? I just need to retain the pointer to the buffer so that once it has been written, I can read it.
How do I go about this? Using a pointer to a string?
Cheers
Cata
Edit: Thanks dude! I got it figured, switched the string into a pointer, and forwarded the pointer, pulled it out, converted it back... and bingo!
Gratz. My experimentation with COM goes very well indeed 
|
|
|
|
|
Did you ever read all that stuff on marshaling I gave you links for before? ref and out should only be used for [out] value types and pointers to pointers as declared in native code. If you need the address to a string, you simply do something like this:
IntPtr ptr = Marshal.StringToCoTaskMemAuto(myString); If your method declaration expects a pointer, this is how you can get it. If you're passing a char[] array, the array itself is a reference type (even though Char is a value type) so you don't need ref or out . The address is what's already being passed since the array is a reference type.
It all just depends on the implementation, for which you've given no specifics. If you need help with something specifically, please provide the signature of the method you're trying to call or something similar.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yeah, sorted it all.
Thanks mate, probably posted too soon. Got it figured.
Gratz.
Cata
|
|
|
|
|
I have one form that is subscribing as an EventHandler to an event on the parent form.
It is possible for the user to close this form but still have the parent open.
Is there a way that I can remove myself as a delegate to that event? You know...like a "parent.EventType -= this.EventHandler;"
_____________________________________________
Of all the senses I could possibly lose, It is most often the one called 'common' that gets lost.
|
|
|
|
|
Yeah, same way you add it - you were close:
parent.Event -= new EventHandler(this.handler_Method); You don't even need to hold a reference because a delegate is a managed function pointer and the function (actually, method) doesn't move.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks Heath.
I thought about doing that....but it seems a bit counter-intuitive that you tell the parent to remove a new EventHandler.
Later,
Michael
_____________________________________________
Of all the senses I could possibly lose, It is most often the one called 'common' that gets lost.
|
|
|
|
|
It is only a new delegate but the delegate references the same method (of the same instance), so it will get removed. You can keep a reference to your delegate you added initially if you don't believe me, but trust that it works this way.
As far as who removes event handler is up to your design. If the child form is hooking into its parent form, then the child should remove the event handler for a better OO design. You could do this in the Closing or Closed event if you like, but know that the event handler will be nullified and garbaged collected if the child reference gets destroyed. It really isn't necessary in such a case.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Is there a way to validate a file name in C#?
I know I could easily code this up myself, but this is something everyone always needs, so I am in total denial that there is no function like that in C# libraries.
Thanks,
Elena
|
|
|
|
|
What do you mean validate a file name? Validate how? That it matches some naming scheme, is a certain length? Then the answer is no.
|
|
|
|
|
Try creating a file using an invalid file name and see if an exception happens, and handle the exception.
|
|
|
|
|
After playing with XML Web Services a little bit, it looks like all the data members of any custom object that need to be serialized across should be marked as public. This seems so non O-Oish or is this a limitation of the WSDL that gets generated automatically that it only supports public data members.
For e.g.
[Serializable]<br />
public class SomeData <br />
{<br />
public string _id;
<br />
public string Id <br />
{<br />
get { return _id; }<br />
}<br />
}<br />
Is there a way around this?
Chen Venkataraman
|
|
|
|
|
It's due to the way xml serialization works. It doesn't actually remote the object like you would think. What happens is that wsdl.exe creates a class on the client that is serialziation comatible with your class, with none of the methods. It will just be a simple struct with data fields only.
|
|
|
|
|
Only the property needs to be public. Your field that stores the actual value should be marked private. You want WSDL to ignore it and only pay attention to the public property. After all, why include values for both _id and Id, which actually are the same object?
If you want more control over the WSDL that's generated, see the attributes in the System.Xml.Serialization namespace, as well as those in the System.Web.Services and System.Web.Services.Protocols namespaces.
There is plenty of documentation about these in the .NET Framework SDK.
Besides, remember that the Web Service is just another class that code can call via a proxy. Classes can only access public members of other classes unless they're derived from that class. This is how code access is supposed to work.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
XML Serialization only serializes public data.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpovrSerializingObjects.asp
Chen Venkataraman wrote:
Is there a way around this? Yes
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemRuntimeSerializationISerializableClassTopic.asp
Or you can do a binary serialization to a MemoryStream and send it as a byte array. I have used this method successfully with an intermediate compression/encryption pass.
|
|
|
|
|
What I'm trying to do is have a tree view on the left of my SDI view, and depending on what's selected in that, display a different "form" or view on the right hand side. I'll want to have a dynamic amount of views, depending on how many items are in the tree view. All the data in the different views will be updated constantly, but only the selected one will display.
Any ideas how to accomplish this?
The Tab Control looks promising, but I'm wondering if there's another way, and I don't want the actual tab, because selection will be done via the tree control.
Thanks,
Peter
|
|
|
|