|
Well, if I do start reading from the bottom I will get the information I need then be able to close the stream read and go on to the next file. The data that needs to be read is at the very bottom of the file. I just don't know how to start reading from the end of the file.
Thanx for the reply!
Jude
|
|
|
|
|
Hi,
have a look at FileStream.Seek() or FileStream.Position which will allow you to read
into a byte[] the last N bytes of a file.
|
|
|
|
|
I have some problems with microsoft´s example under void GetObjectData(SerializationInfo info, StreamingContext context) in MSDN VS5. I have executed the code and it´s running, but when I remove formatter.Serialize(fs, a1) and try to Deserialize the binary file, it fails.
Have I misunderstod the example or What is wrong? Can I fix the code I need to serialize a singleton.
Best regards, Gywox
Modified Example:
<br />
using System;<br />
using System.Web;<br />
using System.IO;<br />
using System.Collections;<br />
using System.Runtime.Serialization.Formatters.Binary;<br />
using System.Runtime.Serialization;<br />
using System.Security.Permissions;<br />
<br />
[Serializable]<br />
public sealed class Singleton : ISerializable<br />
{<br />
private static readonly Singleton theOneObject = new Singleton();<br />
private string someString_value;<br />
private Int32 someNumber_value;<br />
<br />
public string SomeString<br />
{<br />
get<br />
{<br />
return someString_value;<br />
}<br />
set<br />
{<br />
someString_value = value;<br />
}<br />
}<br />
<br />
public Int32 SomeNumber<br />
{<br />
get<br />
{<br />
return someNumber_value;<br />
}<br />
set<br />
{<br />
someNumber_value = value;<br />
}<br />
}<br />
<br />
private Singleton()<br />
{<br />
}<br />
<br />
public static Singleton GetSingleton()<br />
{<br />
return theOneObject;<br />
}<br />
<br />
[SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]<br />
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)<br />
{<br />
info.SetType(typeof(SingletonSerializationHelper));<br />
}<br />
}<br />
<br />
<br />
[Serializable]<br />
internal sealed class SingletonSerializationHelper : IObjectReference<br />
{<br />
public Object GetRealObject(StreamingContext context)<br />
{<br />
return Singleton.GetSingleton();<br />
}<br />
}<br />
<br />
class App<br />
{<br />
[STAThread]<br />
static void Main()<br />
{<br />
FileStream fs = new FileStream("DataFile.dat", FileMode.OpenOrCreate);<br />
<br />
try<br />
{<br />
BinaryFormatter formatter = new BinaryFormatter();<br />
<br />
Singleton[] a2 = (Singleton[])formatter.Deserialize(fs);<br />
Console.WriteLine("Do both array elements refer to the same object? " + (a2[0] == a2[1]));<br />
Console.WriteLine(a2[0].SomeString + " " + a2[0].SomeNumber);<br />
Console.WriteLine(a2[1].SomeString + " " + a2[1].SomeNumber);<br />
}<br />
catch (SerializationException e)<br />
{<br />
Console.WriteLine("Failed to serialize. Reason: " + e.Message);<br />
throw;<br />
}<br />
finally<br />
{<br />
fs.Close();<br />
}<br />
}<br />
}
|
|
|
|
|
Below is what I use for serialization. It seems to work fine for me?
public void GetObjectData(SerializationInfo info, StreamingContext context){
info.AddValue("id", id);
info.AddValue("applicationId", applicationId);
}
public MyObject(SerializationInfo info, StreamingContext context) {
id = info.GetInt64("id");
applicationId = info.GetInt64("applicationId");
}
File Not Found
|
|
|
|
|
Hi!
Some source code, please.
How do you manage to Serialize/Deserialize a Singleton?
Singleton.Instance = (Singleton)formatter.Deserialize(fs); // Error Singleton is readonly
/Gywox
|
|
|
|
|
Use the System.Xml.Serialization.XmlSerializer class to serialize. As for managing a Singleton that is not a serialization issue but a design issue. But for grins and giggles, in the serialization constructor overwrite your static instance for the singleton.
formatter.Deserialize(fs);
public SomeConstructor(SerializationInfo info, StreamingContext context) {
...
SomeConstructor.me = this;
}
File Not Found
|
|
|
|
|
Hi, I got stuck in a problem and don't know what to do. In my web form. I am trying to display a ModalPopup window(Ajax) when I click on a link button. It gets displayed behind the flash image object which i have in the center of my web form. The modalpopup works completely fine if i remove the flash image object.
I need to make this working is there a way to do. Please help me
Thanks
|
|
|
|
|
I was trying to allow a user to resize one of the panels on my form (by moving arrowicons). However I get these errors.
'System.Windows.Forms.Control.Location' because it is not a variable
'System.Windows.Forms.Control.Size' because it is not a variable
here is what I was trying to do:
AOIpanel.Location.X = leftEdgeArrow.Location.X;
AOIpanel.Location.Y = (centerArrow.Location.Y +(AOIpanel.Size.Height/2));
AOIpanel.Size.Width = (rightEdgeArrow.Location.X - leftEdgeArrow.Location.X);
-- modified at 16:24 Wednesday 21st February, 2007
|
|
|
|
|
Hi,
setting Control.Location.X or Control.Size.Width does not help
(see the remark at Control.Location).
if you want to change the Location or Size you must either use "new Point()" or "new Size()",
or the properties Left, Top, Width, Height.
But it would not generate the errors you mention either (unless the code you are showing is not
actually the code you are compiling). I assume you tried to use Location.X etc. as an
out or ref parameter, which is impossible, out/ref requires a variable, a struct or
a class object, but not a part of them (such as a struct field).
|
|
|
|
|
Hi Guys!
I am having a weird problem with one of our computers here at work, my application uses crystal report viewer with C# application designed in VS2003. All computers print the report just fine but this one computer prints a few rows and columns and then cuts off the rest of the print and if the user goes back and tries to print again the same report then it prints just fine. I am not sure why this is happening, could it be the printer driver.
PLEASE HELP!!!
sasa
|
|
|
|
|
Is it possible to make the mouse pointer follow moving objects on the screen?
|
|
|
|
|
|
I have an application that save some sort of information in a an xml file. I want to control that application remotely so I want to save that xml file in a web service.
I want to how I can save an xml file via a web service
|
|
|
|
|
Accept an XmlDocument as the parameter to the webservice. Then call the save method.
[WebMethod]
public string SaveXml(XmlDocument document){
string fileName = Guid.NewGuid().ToString();
document.Save(fileName);
return fileName;
}
File Not Found
|
|
|
|
|
Hi
I have created a webservice with a simple function HelloWorld. It works fine in the client application.
How do I change the default url of the webservice that points to the asmx file? I know that I can change in Reference.cs in the client application. But I want to set the default url other than localhost to point to a server where my asmx file is.
I am using VS 2003, C#.
Thanks a lot in advance
Muthu.
|
|
|
|
|
Click the web reference you want to change. Look in the properties window and change the URL Behavior to Dynamic. This will create an entry in your app.config file (or web.config for web projects). This file can be modified before run time to point to the right place.
Also, if you want to save hours of problems down the road change the Web Reference URL to an invalid URL in the properties panel and rely on the generated key.
A sample app.config entry
<add key="SimpleTest.localhost.Service1" value="http://localhost/testsite/Service1.asmx"/>
<pre>
<div class="ForumSig"><hr><font size="-2">File Not Found
</font></div>
|
|
|
|
|
Dear All,
i have a Unmanaged c++ based Library and i want to use it C# application(i.e. it expose some c based function .. ).. could some one give some pointer to use unmanaged library in c#.. so that i don't have to provide some extra dll or lib with c# to my end user....
thanks in advance
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
ThatsAlok wrote: so that i don't have to provide some extra dll
It doesn't work that way, you will still need to include the C++ dll.
only two letters away from being an asset
|
|
|
|
|
Mark Nischalke wrote: t doesn't work that way, you will still need to include the C++ dll.
i have C++ Library and related Header file.. now if get some pointer to proceed .. that will be great help from your side .. i am little confused how to call these function in c#...
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
|
Mark Nischalke wrote:
Using Unmanaged code and assembler in C#[^]
thats a great article...! sorry if i sounding like child.. could i use to DLLimport to import my ABC.lib.. or i have to use some other method!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
DllImport only works with unmanaged DLLs. An unmanaged static library (LIB) can't be used this way from C#. Only C++/CLI can mix managed and unmanaged code.
As far as I can see you have 4 options:
- Take the sources and convert them to C#.
- Change the unmanaged project to build a DLL and then use DllImport .
- Create a mixed mode (managed - unmanaged) wrapper DLL in C++/CLI.
- Write the client application in C++/CLI.
Regards,
Tim
|
|
|
|
|
I want to paint a particular part of image and display it on the form that is I want to display the picture not its background... I have differentiated between both the background pixels and picture pixels using lock mode and bitmap data. Now how can I display that required portion on the form??? Can any buddy help?????
How can I keeep the bitmap image in buffer just like BufferImage class in java do we have anything like this in C#.......
|
|
|
|
|
If you want to show only certain parts of an image, set all the other pixels to a color ( magenta is good, 255, 0, 255 ), and use the ImageAttributes class and one of the versions of DrawImage that takes it, to draw with transparency
samreengr8 wrote: How can I keeep the bitmap image in buffer just like BufferImage class in java do we have anything like this in C#.......
The image stays in memory if it's in a variable, I assume this is not what you mean ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: use the ImageAttributes class
Can u tell me how to use it If I want to write those pixels on another bitmap image.....
Christian Graus wrote: The image stays in memory if it's in a variable, I assume this is not what you mean ?
No its image that stays in memory I want the bitmapdata and then want to paste another bitmap to merge to bitmaps and then draw it.......
Well thanx 4 ur response
|
|
|
|