Click here to Skip to main content
15,918,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Imports System
Imports System.IO
Imports System.Configuration
Imports System.IO.DirectoryInfo
Imports System.Diagnostics.FileVersionInfo


Public Class SaveScript



Public Sub SaveFile(ByVal scriptcontent As String, ByVal filename As String, ByVal extension As String)
Try

Dim filelocation As String
Dim filepath As String = My.Application.Info.DirectoryPath
filelocation = ConfigurationManager.AppSettings("FilePath") '
filepath = filelocation & filename & extension
Dim objWriter As New System.IO.StreamWriter(filepath)
objWriter.Write(scriptcontent)
objWriter.Close()

Catch ex As Exception

End Try

End Sub
Posted
Updated 4-Feb-14 22:38pm
v2

1 solution

For starters, never try to save in the application exe folder, or any folder below that. It works for development, but is fails in production, because the EXE is in a folder below "Program Files" which requires admin permissions to modify to prevent virus activity.

Instead, see here: Where should I store my data?[^] - it's in C#, but it's pretty obvioius what to do.
 
Share this answer
 
Comments
Alina091 5-Feb-14 5:02am    
@OriginalGriff-Hi-Thanks for the suggestion.I am new to dot net.In my code I have already hard coded a specified path but now I want to redirect under bin of the project.Is
"Dim Directory As String = My.Application.Info.DirectoryPath" is a right way to do it and which namespace does it use?
OriginalGriff 5-Feb-14 5:19am    
Do not try to store anything under the bin of the project - it isn't a good idea at all.
Application is a member of My, and your code compiles on my system: but are you trying to use this on a web applictaion / web site (the ASP.NET part of your question implies you are)?
Alina091 5-Feb-14 7:00am    
@OriginalGriff- Thanks a lot. Appreciate your advice. As you said "I am trying to use this on a web application", It helped me coming to the conclusion. My code worked using Server.MapPath("/Scripts").Thanks :)
OriginalGriff 5-Feb-14 7:08am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900