Fichier

RM50Man Messages postés 314 Date d'inscription mercredi 1 novembre 2000 Statut Membre Dernière intervention 20 août 2006 - 4 janv. 2005 à 21:03
RM50Man Messages postés 314 Date d'inscription mercredi 1 novembre 2000 Statut Membre Dernière intervention 20 août 2006 - 6 janv. 2005 à 11:21
Je cré unn fichier comme ceci
(peut importe l extension du fichier)


FileStream fichierCry
= new FileStream( @"C:\rmman.xls",FileMode
.Create

,FileAccess
.Write
);


et ca bug si le fichier existe deja
alors qu avec create ca doit ecraser le fichier existant

RM50man

15 réponses

MorpionMx Messages postés 3466 Date d'inscription lundi 16 octobre 2000 Statut Membre Dernière intervention 30 octobre 2008 57
4 janv. 2005 à 22:07
Quel est le bug ?



J'ai essayé ceci :



FileStream fichierCry = new FileStream(@"C:\aaa.xls",FileMode.Create,FileAccess.Write);

StreamWriter s = new StreamWriter(fichierCry);

s.WriteLine("aaa");

s.Flush();

s.Close();

fichierCry.Close();



Puis modifié ce que j'ecrivais dedans, etc...

Le fichier est bien créé s'il n'existe pas, et remplacé s'il existe
0
cs_Bidou Messages postés 5487 Date d'inscription dimanche 4 août 2002 Statut Membre Dernière intervention 20 juin 2013 61
4 janv. 2005 à 22:16
Tu peux faire plus simple, dans ton cas cette manière suffirait peut-être.
Utilises un StreamWriter :


StreamWriter sw =
new StreamWriter(path,
false)

Le booleen en deuxième position permet de spécifier si le file doit être overwriter ou pas...

[Pub]
http://www.csharpfr.com/auteurdetail.aspx?ID=13319 [\Pub]
C# forever
0
RM50Man Messages postés 314 Date d'inscription mercredi 1 novembre 2000 Statut Membre Dernière intervention 20 août 2006
4 janv. 2005 à 22:21
Non mé apre sj utilise un binaryReader

RM50man
0
RM50Man Messages postés 314 Date d'inscription mercredi 1 novembre 2000 Statut Membre Dernière intervention 20 août 2006
4 janv. 2005 à 22:22
RM50man
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_coq Messages postés 6349 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 101
4 janv. 2005 à 23:37
Un BinaryReader sur un FileStream ouvert en FileAccess.Write seul ?

Cocoricoooooooo !!!!
coq
MVP Visual C#
0
RM50Man Messages postés 314 Date d'inscription mercredi 1 novembre 2000 Statut Membre Dernière intervention 20 août 2006
4 janv. 2005 à 23:39
non BinaryWriter

RM50man
0
cs_coq Messages postés 6349 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 101
4 janv. 2005 à 23:47
donne les infos sur l'exception, sinon on ne vas pas pouvoir essayer d'aider

Cocoricoooooooo !!!!
coq
MVP Visual C#
0
RM50Man Messages postés 314 Date d'inscription mercredi 1 novembre 2000 Statut Membre Dernière intervention 20 août 2006
4 janv. 2005 à 23:54
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.


************** Exception Text **************
System.IO.IOException: The file "C:\Diapositive3.GIF" already exists.
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)
at Cryptage.MainForm.Crypt(String cle) in c:\Documents and Settings\REGIS\Mes documents\SharpDevelop Projects\Cryptage\MainForm.cs:line 664
at Cryptage.MainForm.Button1Click(Object sender, EventArgs e) in c:\Documents and Settings\REGIS\Mes documents\SharpDevelop Projects\Cryptage\MainForm.cs:line 618
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)



************** Loaded Assemblies **************
mscorlib
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase: [file:///c:/windows/microsoft.net/framework/v1.1.4322/mscorlib.dll file:///c:/windows/microsoft.net/framework/v1.1.4322/mscorlib.dll]
----------------------------------------
Cryptage
Assembly Version: 1.0.1830.42803
Win32 Version: 1.0.1830.42803
CodeBase: [file:///C:/Documents%20and%20Settings/REGIS/Mes%20documents/SharpDevelop%20Projects/Cryptage/bin/Debug/Cryptage.exe file:///C:/Documents%20and%20Settings/REGIS/Mes%20documents/SharpDevelop%20Projects/Cryptage/bin/Debug/Cryptage.exe]
----------------------------------------
System.Windows.Forms
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase: [file:///c:/windows/assembly/gac/system.windows.forms/1.0.5000.0__b77a5c561934e089/system.windows.forms.dll file:///c:/windows/assembly/gac/system.windows.forms/1.0.5000.0__b77a5c561934e089/system.windows.forms.dll]
----------------------------------------
System
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase: [file:///c:/windows/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll file:///c:/windows/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll]
----------------------------------------
System.Drawing
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase: [file:///c:/windows/assembly/gac/system.drawing/1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll file:///c:/windows/assembly/gac/system.drawing/1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll]
----------------------------------------
System.Xml
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase: [file:///c:/windows/assembly/gac/system.xml/1.0.5000.0__b77a5c561934e089/system.xml.dll file:///c:/windows/assembly/gac/system.xml/1.0.5000.0__b77a5c561934e089/system.xml.dll]
----------------------------------------


************** JIT Debugging **************
To enable just in time (JIT) debugging, the config file for this
application or machine (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.


For example:


<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>


When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the machine
rather than being handled by this dialog.



RM50man
0
MorpionMx Messages postés 3466 Date d'inscription lundi 16 octobre 2000 Statut Membre Dernière intervention 30 octobre 2008 57
5 janv. 2005 à 09:28
Et un ptit bout de code aussi, ca nous aiderais peut-etre un peu plus.

Pour le moment, je vois pas.
0
cs_coq Messages postés 6349 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 101
5 janv. 2005 à 09:55
La seule façon d'obtenir cette erreur avec le constructeur de FileStream que je connaisse est de mettre FileMode.CreateNew
Donc il doit y avoir un problème ailleurs.

Cocoricoooooooo !!!!
coq
MVP Visual C#
0
APWEB Messages postés 74 Date d'inscription lundi 30 juin 2003 Statut Membre Dernière intervention 18 octobre 2006 2
5 janv. 2005 à 12:53
Est-ce que tout simplement ton fichier ne serait pas en Read-only tout simplement et que cela bloque son ecrasement ???

AP
0
RM50Man Messages postés 314 Date d'inscription mercredi 1 novembre 2000 Statut Membre Dernière intervention 20 août 2006
6 janv. 2005 à 00:03
Ca y est g regle le probleme!!!!!!!!!!!

RM50man
0
cs_coq Messages postés 6349 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 101
6 janv. 2005 à 08:51
et si tu nous donnais la solution ?

Cocoricoooooooo !!!!
coq
MVP Visual C#
0
RM50Man Messages postés 314 Date d'inscription mercredi 1 novembre 2000 Statut Membre Dernière intervention 20 août 2006
6 janv. 2005 à 11:16
J'ai tout simplement capturer l'exception.

RM50man
0
RM50Man Messages postés 314 Date d'inscription mercredi 1 novembre 2000 Statut Membre Dernière intervention 20 août 2006
6 janv. 2005 à 11:21
Allez voir le programme final!!!

http://www.csharpfr.com/code.aspx?ID=28644

RM50man
0
Rejoignez-nous