![]() |
|
[HELP] Save File Fialog/Stream Writer - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Visual Basic & .NET Framework (https://sinister.li/Forum-Visual-Basic-NET-Framework) +--- Thread: [HELP] Save File Fialog/Stream Writer (/Thread-HELP-Save-File-Fialog-Stream-Writer) |
[HELP] Save File Fialog/Stream Writer - 1llusion - 02-22-2011 Hi, well, I was working on a little generator and I came across a problem, For some reason, I keep getting "Cannot acess file.php because it is allready used by another process" Code: Dim ofd, ofd2 As New SaveFileDialog
Dim SWE As Stream
ofd.Filter = "php files (*.php)|*.php|All files (*.*)|*.*"
ofd.ShowDialog()
File.Create(ofd.FileName)
SWE = ofd.OpenFile()
Using sw As StreamWriter = New StreamWriter(SWE)
sw.WriteLine("<?php")
sw.WriteLine("$action = $_GET['action'];")
sw.WriteLine("$data = $_GET['data'];")
sw.WriteLine("if ($action == " & Chr(34) & "delete" & Chr(34) & "){")
sw.WriteLine("unlink(" & Chr(34) & "log.txt" & Chr(34) & ");")
sw.WriteLine("$new = fopen(" & Chr(34) & "log.txt" & Chr(34) & ", 'a');")
sw.WriteLine("fclose($new);")
sw.WriteLine("}")
sw.WriteLine("if ($action == " & Chr(34) & "write" & Chr(34) & "){")
sw.WriteLine("$open = fopen(" & Chr(34) & "log.txt" & Chr(34) & ", 'a');")
sw.WriteLine("fwrite($open, $data." & Chr(34) & "\n" & Chr(34) & ");")
sw.WriteLine("fclose($open);")
sw.WriteLine("}")
sw.WriteLine("?>")
sw.Close()
End Usingthanks for any help
RE: [HELP] Save File Fialog/Stream Writer - Coder-san - 02-23-2011 Just remove the File.Create. Here is the whole code: Code: Dim saveDialog As New SaveFileDialog
Dim aStream As IO.Stream
saveDialog.Filter = "php files (*.php)|*.php|All files (*.*)|*.*"
If saveDialog.ShowDialog = 1 Then
aStream = saveDialog.OpenFile()
Using sw As IO.StreamWriter = New IO.StreamWriter(aStream)
sw.WriteLine("<?php")
sw.WriteLine("$action = $_GET['action'];")
sw.WriteLine("$data = $_GET['data'];")
sw.WriteLine("if ($action == """"delete""""){")
sw.WriteLine("unlink(""""log.txt"""");")
sw.WriteLine("$new = fopen(""""log.txt"""", 'a');")
sw.WriteLine("fclose($new);")
sw.WriteLine("}")
sw.WriteLine("if ($action == """"write""""){")
sw.WriteLine("$open = fopen(""""log.txt"""", 'a');")
sw.WriteLine("fwrite($open, $data.""""\n"""");")
sw.WriteLine("fclose($open);")
sw.WriteLine("}")
sw.WriteLine("?>")
sw.Close()
End Using
End IfRE: [HELP] Save File Fialog/Stream Writer - 1llusion - 02-23-2011 (02-23-2011, 07:23 AM)Coder-san Wrote: Just remove the File.Create. Thanks ![]() And, the """"write"""", how does that work? thanks
RE: [HELP] Save File Fialog/Stream Writer - Coder-san - 02-23-2011 Inside double-quotes, double-quotes will appear when there are 4 continuous double-quotes. For opening and closing, you need three of them. RE: [HELP] Save File Fialog/Stream Writer - 1llusion - 02-23-2011 (02-23-2011, 09:44 AM)Coder-san Wrote: Inside double-quotes, double-quotes will appear when there are 4 continuous double-quotes. oh cool yay no more & Chr(34 or w/e its the number) &.... ![]() Thanks
|