Create a file via Windows Service

Discussion in 'ASP .Net' started by vishal, Oct 28, 2004.

  1. vishal

    vishal Guest

    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
     
    vishal, Oct 28, 2004
    #1
    1. Advertising

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

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

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

    --
    Ben Strackany
    www.developmentnow.com


    "vishal" <> wrote in message
    news:1b5d01c4bd03$abe74af0$...
    > 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
     
    Ben Strackany, Oct 28, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Scott Ocamb

    Load Web Page via Windows Form or Service

    Scott Ocamb, Oct 10, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,160
    Jared
    Oct 11, 2004
  2. JPractitioner
    Replies:
    16
    Views:
    23,611
    liquid
    Mar 28, 2007
  3. Rob
    Replies:
    3
    Views:
    507
    Steven Cheng[MSFT]
    Feb 3, 2006
  4. Replies:
    1
    Views:
    192
    Andrew Brook
    Aug 2, 2006
  5. Replies:
    1
    Views:
    146
    Van den Driessche Willy
    Sep 20, 2006
Loading...

Share This Page