473,503 Members | 1,692 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create a file via Windows Service

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
Nov 18 '05 #1
1 1248
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" <an*******@discussions.microsoft.com> wrote in message
news:1b****************************@phx.gbl...
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

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1279
by: Nate | last post by:
Hi All, I am having difficulty creating a new instance of a proxy for an XML Web Service in my Web Form Client (VB) .NET code. When I try to run my 'hello world' file, hw.aspx, I receive the...
1
3390
by: James Proctor | last post by:
Hi there, im brand new to ASP. Ive done loads of VB coding and one of my clients is intrested in a web based application, so im trying to play on and learn it a tad. However im comming across lots...
10
4925
by: robwharram | last post by:
Hi, I'm quite frustrated in the fact that I can't even display a simple "Hello World" message on .Net. I've been through all of the groups and searched all over the place and haven't been able...
3
14850
by: Amjad | last post by:
Hi, I just wrote a test Windows Service that creates a text file on startup (please see my code below). The file is never created. Protected Overrides Sub OnStart(ByVal args() As String) Dim...
6
3349
by: JonSteng | last post by:
..Net Visual Studio Professional 2003 Version 7.1.3088 ..Net Framework 1.1 SP1 Version 1.1.4322 IIS 5.1 Windows XP Professional SP2 Micron T3000 Laptop (1.5 GHz; 1GB RAM; 40GB HD with 17GB Free)...
3
1526
by: gerard.mears | last post by:
Hi, I'm a total newbie at VB.NET so please bare with me. I would like to create a simple service that will log all exe and com files that are executed but I don't know where to start. I'm...
1
14745
by: drk.kumar | last post by:
I have an implementation issue with WMI scripts to check the user machine processor. The implementation is working fine in the local machine (Windows XP operating system). It is throwing script...
0
1063
by: ricoiii | last post by:
Hello, i have created a service in vb.net 2005 and want to create an access-database at runtime. The code is: Dim cat As ADOX.Catalog cat = CreateObject("ADOX.Catalog") If...
10
2129
by: =?Utf-8?B?cm1jb21wdXRl?= | last post by:
I have Windows 2000 and recently included Internet Information Services. I then created a simple ASP file and clicked on it. The Open With dialog appears asking me to select a program. I copied...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7074
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...
1
6982
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5572
agi2029
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,...
1
5000
isladogs
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...
0
4667
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3161
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...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
374
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.