Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27201

VS 2012 Open Text Files Without Permission

$
0
0
How To Open Text Files Without Permission:

[Working 2013]

Imports System.IO

Public Class Form1

Public Sub opentext(ByVal txt As String)
Try
Dim sr As StreamReader = New StreamReader(txt)
r1.Text = sr.ReadToEnd()
sr.Close()
Catch : MsgBox(ErrorToString)
End Try
End Sub

Private Sub b1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b1.Click
Dim Path As String = Application.StartupPath
Dim s As String = Path.Replace("file" & ":\", "")
s = s & "\Resources\Txt\File1.txt"
opentext(s)
End Sub

End Class

How it works:

Your are not allowed to open text files through reflection or startup paths, etc,
you will be given the URI exception, or access is denied.. This works because it calls
file, and :\ as two different strings and brings them together.

Simple yes? :)

How to use:

Create a folder application startup path, and replace this line:

"\Resources\Txt\File1.txt"

With your folder, subfolder, file, etc.

Hope it helps, *sigh* vb isn't a personal choice of mine, just figured id get it out the
way.. came across this, posted, hope it helps as I don't comprehend why it "has" to be
done this way / similar. :eek:

Viewing all articles
Browse latest Browse all 27201

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>