Hey im serializing objects to files am i forgeting something
it works great but once they are written i dont have access to deleting
them or overwriting them..
my folder properties are everyone can update delete and read and write
i set everything to everyone... juste to be sure.
and the owner of the file is the application is question...
heres my code
Alexandre (Al*****************@gmail.com)
public static void save(string dir,string file, object o)
{
try
{
if(File.Exists(dir+file))
{
File.Delete(dir+file);
}
Stream stream = new
FileStream(dir+file,FileMode.Create,FileAccess.Wri te);
IFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream,o);
stream.Close();
}
catch(Exception e)
{
throw (new Exception(dir+file + " save ->> " +
e.Message));
}
} 9 2548
Alexandre <al*****************@gmail.com> wrote: Hey im serializing objects to files am i forgeting something it works great but once they are written i dont have access to deleting them or overwriting them.. my folder properties are everyone can update delete and read and write i set everything to everyone... juste to be sure. and the owner of the file is the application is question...
Could you post a short but *complete* program which demonstrates the
problem?
See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
Note that you should use a using statement with your stream, so that
even if the formatting fails, you still close the file.
(You should also use Path.Combine to go from directory and filename to
fully qualified filename.)
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Could you post the error message you're getting?
Can you also give an example of a class marked with serializable attribute
and an example of how you call the static save() method. I have copy+pasted
your code and I have created a small test class and it works fine here.
Gabriel Lozano-Morán
Software Engineer
Sogeti
"Alexandre" <al*****************@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com... Hey im serializing objects to files am i forgeting something it works great but once they are written i dont have access to deleting them or overwriting them.. my folder properties are everyone can update delete and read and write i set everything to everyone... juste to be sure. and the owner of the file is the application is question...
heres my code
Alexandre (Al*****************@gmail.com)
public static void save(string dir,string file, object o) { try { if(File.Exists(dir+file)) { File.Delete(dir+file); } Stream stream = new FileStream(dir+file,FileMode.Create,FileAccess.Wri te); IFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream,o);
stream.Close(); } catch(Exception e) { throw (new Exception(dir+file + " save ->> " + e.Message)); } }
since i rebuilt my application,
webservice and web application and assembly
and since i also disconnected from my ftp (to the webservice folder)
the access denied has stoped and the service runs exacly has it
should... for some odd reason,
what i was doing was saving locally a serialized version of the user
object so when i update user information it had an access denied on the
serialization of the object and on the delete of the object, in turn it
was not removing the ram object from the hash map that contained it.
when retreiving an object this is what i do,
check ram --> check hard drive --> fetch from sql db
so im stopping as many requests from reaching the database and im aslo
limiting the creation of new objects...
Jon mentioned "using" ive seen it alot but never understood how to use
it, i know what it does i just dont know how ... exactly
Path.Combine <-- my object locations are working properly as they are
what could Path.Combine make better ?
Alexandre
Alexandre <al*****************@gmail.com> wrote: Jon mentioned "using" ive seen it alot but never understood how to use it, i know what it does i just dont know how ... exactly
It basically inserts a try/finally block into your code automatically,
calling Dispose at the end of the block. It's much easier to get
reliable code which properly disposes of resources in the face of
exceptions that way.
Path.Combine <-- my object locations are working properly as they are what could Path.Combine make better ?
It would mean that you wouldn't need to make sure you had a directory
separator at the end of one of your strings, for one thing.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
thats interesting, at the moment the separator is an integral part of
my app its handeled by the app its self... since im doing a
server.mappath and a couple things in my auto manipulation... but i
will heep in mind your comments...
i need to find a good example of using(object) { .. } because every
example ive seen got me a bit confused so far...
Alexandre ( www.pointnetsolutions.com) <al*****************@gmail.com>
wrote: thats interesting, at the moment the separator is an integral part of my app its handeled by the app its self... since im doing a server.mappath and a couple things in my auto manipulation... but i will heep in mind your comments...
i need to find a good example of using(object) { .. } because every example ive seen got me a bit confused so far...
Well, in the code you've got, you'd change it to:
using (Stream stream = new FileStream
(dir+file,FileMode.Create,FileAccess.Write))
{
IFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream,o);
}
then even if formatting throws an exception, you'll still close the
stream.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
hey Jon,
i tryed changing what you told me, but for some odd reasion it does not
work,
from time to time it stops working and i get errors again ..
any thoughts ?
Alexandre ( www.pointnetsolutions.com) <al*****************@gmail.com>
wrote: i tryed changing what you told me, but for some odd reasion it does not work, from time to time it stops working and i get errors again ..
any thoughts ?
Well, what errors are you getting?
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: nb |
last post by:
What kind of problems is c++ best at solving?
|
by: Praveen K |
last post by:
I have a problem in communicating between the C# and the Excel Interop
objects. The problem is something as described below.
I use Microsoft Office-XP PIA dll’s as these dll’s were been...
|
by: ma740988 |
last post by:
Trying to some of my reading on file manipulation
(ifstream/ofstream/fstream) into action. So now consider.
# include <iostream>
# include <fstream>
# include <cstring>
# include <sstream>
...
|
by: L'eau Prosper Research |
last post by:
Press Release:
L'eau Prosper Research (Website: http://www.leauprosper.com) releases
new TradeStation 8 Add-on - L'eau Prosper Market Manipulation
Profiling Tools Set.
L'eau Prosper Market...
|
by: L'eau Prosper Research |
last post by:
NEW TradeStation 8 Add-on - L'eau Prosper Market Manipulation
Profiling Tools Set By L'eau Prosper Research
Press Release:
L'eau Prosper Research (Website: http://www.leauprosper.com) releases...
| |
by: Wayne Shu |
last post by:
Today when I read TC++PL(se) section 4.8 Enumerations, I get some
problems.
1. In an enumeration, why the value of some enumerators can be the
same, for instance:
enum e1{a = 0, b = 0, c = 0};...
|
by: Juha S. |
last post by:
Hi,
I'm writing a small text editor type application with Python 2.5 and
Tkinter. I'm using the Tk text widget for input and output, and the
problem is that when I try to save its contents to a...
|
by: jacob navia |
last post by:
As many people know, I think that garbage collection is a good
solution for many memory allocation problems.
I am aware however, that nothing is "the silver bullet", not
even the GC.
A recent...
|
by: pakerly |
last post by:
How would i do this, convert a test file to excel?
Lets say my text file has fields like this:
NUMBER NAME ADDRESS PHONE
11002 Test1 ...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |