Create a file via Windows Service

V

vishal

Hello,

I have a created a windows service and now I need to
create some files from that windows service. The files
should be located in the following folder: /root/news/
Unfortunaly when the service runs then it throughs the
following error message and therefore it doesnt create the
file.

URI formats are not supported.

Here is my code:

Dim fp As StreamWriter
Try
'fp = File.CreateText(Server.MapPath("/news/")
& strPostPath)
Dim strPath =
System.Reflection.Assembly.GetExecutingAssembly().GetName
().CodeBase
fp = File.CreateText(strPath & "/news/" &
strPostPath)

fp.WriteLine("<p>" &
System.Web.HttpUtility.HtmlDecode(strPost) & "</p>")

' Close the stream writer
fp.Close()
Catch err As Exception
MyLog.Source = "Service1"
MyLog.WriteEntry("CREATE_FILE_ERROR:" &
err.Message)
Finally
End Try
 
B

Ben Strackany

Try using backslashes when creating the file, e.g.

File.CreateText(strPath & "\news\" & strPostPath)

Also, I'm assuming you're defining strPostPath somewhere.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top