How to Make a File Name appear as Form Text - vb.net

I am creating a text editor in VB.net with tabs and I am done so far. All I need is when the user saves the document or opens a document the name of the document shows up on the tab. I am using a separate tab control. I have it done but it shows the whole directory of the file. The only way to change the text on the tab is to change the text of the form I am using for the tab control to duplicate. So my code for when the user opens a file is:
Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
Dim alltext As String
filename = OpenFileDialog1.FileName
alltext = File.ReadAllText(filename)
FastColoredTextBox1.Text = alltext
Me.Text = filename
End Sub
But like I said it shows the whole directory of the file. Is there any way to make it just show the file name. The code for when the user saves the file has the same thing.

Try this:
Me.Text = System.IO.Path.GetFileName(filename)

Related

Save Richtextbox to .txt but same format vb.net2010

when i click the button save, the output of richtextbox1 will be save in .txt,, but my problem is not all the format in richtextbox1 is not desame in .txt that i save. how to fix this?
Private Sub ADD_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ADD.Click
RichTextBox1.AppendText(OutputTstm.Text & " " & vbNewLine)
RichTextBox1.AppendText("*********************" + vbNewLine)
End Sub
Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
Dim isave As New SaveFileDialog
isave.Filter = "txt files (.txt) |*.txt"
isave.FilterIndex = 2
isave.RestoreDirectory = False
If isave.ShowDialog = DialogResult.OK Then
IO.File.WriteAllText(isave.FileName, RichTextBox1.Text)
End If
End Sub
![Richtextbox1 to Notepad ][1]ck.imgur.com/Lw6gz.png
The Text of the RichTextBox is just like the Text of a regular TextBox. It is the Rtf property that contains all the markup and thus all the formatting.
The thing is, you don't need to use either property to save the contents to a file. The RichTextBox has a SaveFile method that lets you save either plain text or Rich Text Format (RTF).
There is a corresponding LoadFile method to read a file into the control.
Also, if you're saving RTFrather than plain text, you should be using the ".rtf" extension rather than ".txt".
There is a function in the RichTextBox Class, that allows saving a file without needing to use a StreamReader.
It's RichTextBox.SaveFile().
There are arguments required by this function, and the ones you need are RichTextBox.SaveFile(FileName As String, FileType As RichTextBoxStreamType)
With those arguments, the code you need is RichTextBox1.SaveFile(isave.FileName, RichTextBoxStreamType.PlainText)

Asp.Net, VB, SQL Server Reporting Services..dynamically generated reports from directory to be viewed on report viewer on click?

I have an aspx webform that in it's vb code reads files that are .rdl from a directory and then lists them as say a button or hyper link etc. "reports are on local host report server"
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim FileLocation As DirectoryInfo = _
New DirectoryInfo("C:\inetpub\wwwroot\Reports")
Dim fi As FileInfo() = FileLocation.GetFiles("*.rdl")
For Each name As FileInfo In fi
' Dim i As Integer
Dim listed As New LinkButton
' listed.Attributes("CssClass") = "a"
' listed.Attributes("Class") = "a"
listed.Attributes("id") = "listed"
listed.Text = (name.Name)
mine.Controls.Add(listed)
'mine.InnerHtml = ""
'i = i + 1
Next
End Sub
and another that has a reportviewer. When a report was clicked, how can I send the name/value to the viewer and redirect to it?
Thank you very much
EDIT: i got to make the click redirect to the viewer with a string and have the viewer use that string,but with how much ever variation ive tried it still errors that
The path of the item 'salesreport.rdl' is not valid. The full path must be less than 260 characters long; other restrictions apply. If the report server is in native mode, the path must start with slash. (rsInvalidItemPath)
this is the viewer code
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
' Retrieve parameter from Route "Reports/{reportName}"
Dim reportName = Picks.Selecty
'Page.Title = reportName
ReportViewer1.ProcessingMode = ProcessingMode.Remote
Dim serverReport As ServerReport
ServerReport = ReportViewer1.ServerReport
serverReport.ReportServerUrl = New Uri("http://localhost/reportserver/")
serverReport.ReportPath = reportName
' reportName
'
' add parameters here
'Dim param As New ReportParameter("name", "value")
'serverReport.SetParameters(param)
serverReport.Refresh()
End If
End Sub
You could try the following.
Create a new page say ReportViewer.aspx which hosts your ReportViewer Control that recieves the name of the .RDL file as a query string.
In the First .aspx page, for every link you display, point the NavigateURL property to ReportViewer.aspx page and pass the name of the .RDL file as a QueryString.
Hope that helps
Thanks,
Prawin

VB.NET Set Default Text Editor

I have created my own text editor in Visual Basic 2013. I want to open text files with it from outside the application: to open them from the Desktop with double click or right click and open with.
I tried to use right click and open with but it doesn't work, it just opens up my application.
How I make my text editor the one that I open text files with?
You would have to use something like the Environment.GetCommandLineArgs method.
Put this in your form load event:
Dim CommandLineArguments() As String = Environment.GetCommandLineArgs()
If CommandLineArguments.Length >= 2 AndAlso String.IsNullOrEmpty(CommandLineArguments(1)) = False AndAlso IO.File.Exists(CommandLineArguments(1)) Then
Me.TextBox1.Text = IO.File.ReadAllText(CommandLineArguments(1))
End If
This will get the command line arguments sent to your application (which is the path to the file you are trying to open with your app) and check if the argument is an existing file. If so, it will read all the file's text into your TextBox.
Write this code in the form load event.
Private Sub form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim fname As String = Command$()
If Not fname = "" Then
fname = Replace(fname, Chr(34), "")
Dim obj As New System.IO.StreamReader(fname.ToString)
RichTextBox1.Rtf = obj.ReadToEnd
obj.Close()
Me.Text = "Your Application Name " & fname
End If
End Sub

Trouble saving ALL listbox data

Ok, so i'm trying to make an Injector. To load the DLLs, I used a File Dialog to select the DLL then write the info to a List Box. Now I want to save the data in the list box and reload the past data on the Form Load, but every method I have tried only saves the name of the DLL not the other info such as Location.
I would like to have no external files IF possible. Any solutions?
Cheers.
Edit: Source code for Open File Dialog
Private Sub OpenFileDialog1_FileOk(sender As Object, e As
System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
Dim FileName As String = OpenFileDialog1.FileName.Substring(OpenFileDialog1.FileName.LastIndexOf("\"))
Dim DLLfileName As String = FileName.Replace("\", "")
ListBox1.Items.Add(DLLfileName)
dlls.Add(DLLfileName, OpenFileDialog1.FileName)
End Sub

Visual Basic Form. How to let users save text file where they want

Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
Dim CurrentDir As String = Environment.CurrentDirectory
Dim OutputFile2 As String = IO.Path.Combine(CurrentDir, "input.txt")
IO.File.WriteAllLines(OutputFile2, Result1.Lines)
End Sub
Right now, I have coding that saves a text file in the current directory. However, I want to have a browse button for users so that they can pick where this text file is saved. How do I proceed this?
I was trying it by my self and I'm having a trouble with using save file dialog. If you can teach me how to use a save file dialog or anyway to write save browse button, I would very appreciate it!
The documentation for the SaveFileDialog object contains an example.
Here is a tutorial on how to implement SaveFileDialog using Toolbox in Visual Studio like you mentioned. The code sample is in C# but it can be easily converted to VB.
Link: www.dotnetperls.com/savefiledialog
Private Sub button1_Click(sender As Object, e As EventArgs)
' When user clicks button, show the dialog.
saveFileDialog1.ShowDialog()
End Sub
Private Sub saveFileDialog1_FileOk(sender As Object, e As CancelEventArgs)
' Get file name.
Dim name As String = saveFileDialog1.FileName
' Write to the file name selected.
' ... You can write the text from a TextBox instead of a string literal.
File.WriteAllText(name, "test")
End Sub