none
Start file after savefile dialog RRS feed

  • Question

  • Hello,

    With this i save a file .

    But after saving i want to start the file

      Using sfd As New SaveFileDialog
                            sfd.Filter = "Excel file|*.xlsx"
                            sfd.FileName = Form1.Name.Text & " - " & Form1.Date.Text
                            sfd.AddExtension = True
                            If sfd.ShowDialog = DialogResult.OK Then
                                If System.IO.File.Exists(sfd.FileName) Then
    
                                Else
    
                                    My.Computer.FileSystem.CopyFile(My.Application.Info.DirectoryPath & "\W10\Test.xlsx", sfd.FileName)
                                  
                                End If
    
                            End If
                        End Using
                    End If
    

    But after saving i want to start the file

    i tryed this but no luck

     System.Diagnostics.Process.Start(sfd.FileName)
                                    WindowState = 1

    Sunday, April 7, 2019 11:40 AM

Answers

  • I changed it a little bit , it is working now

     Using sfd As New SaveFileDialog
                            sfd.Filter = "Excel file|*.xlsx"
                            sfd.FileName = Form1.Name.Text & " - " & Form1.Date.Text
                            sfd.AddExtension = True
                            If sfd.ShowDialog = DialogResult.OK Then
                                Extension.Text = (sfd.FileName)
                                If System.IO.File.Exists(sfd.FileName) Then
    
                                Else
                                    My.Computer.FileSystem.CopyFile(My.Application.Info.DirectoryPath & "\W10\Test.xlsx", sfd.FileName)
                                End If
                            End If
                        End Using
                    End If
                    System.Diagnostics.Process.Start(Extension.Text)
                    WindowState = 1
                End If
    I put the full savefiledialog in the Extension textbox and then start it at the end 

    • Marked as answer by Florishilte Sunday, April 7, 2019 6:35 PM
    Sunday, April 7, 2019 5:38 PM

All replies

  • Hello,

    The basic pattern is shown below.

    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) _
            Handles Button1.Click
    
            Dim fileName As String = "C:\Data\SampleData.xlsx"
    
            Using excelProcess As New Process()
                excelProcess.StartInfo.FileName = fileName
                excelProcess.StartInfo.WindowStyle = ProcessWindowStyle.Minimized
                excelProcess.Start()
            End Using
    
        End Sub
    End Class
    
    In some cases an application may ignore window state, in this case you will have to use extra calls after starting the application 


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Sunday, April 7, 2019 1:15 PM
    Moderator
  • I changed it a little bit , it is working now

     Using sfd As New SaveFileDialog
                            sfd.Filter = "Excel file|*.xlsx"
                            sfd.FileName = Form1.Name.Text & " - " & Form1.Date.Text
                            sfd.AddExtension = True
                            If sfd.ShowDialog = DialogResult.OK Then
                                Extension.Text = (sfd.FileName)
                                If System.IO.File.Exists(sfd.FileName) Then
    
                                Else
                                    My.Computer.FileSystem.CopyFile(My.Application.Info.DirectoryPath & "\W10\Test.xlsx", sfd.FileName)
                                End If
                            End If
                        End Using
                    End If
                    System.Diagnostics.Process.Start(Extension.Text)
                    WindowState = 1
                End If
    I put the full savefiledialog in the Extension textbox and then start it at the end 

    • Marked as answer by Florishilte Sunday, April 7, 2019 6:35 PM
    Sunday, April 7, 2019 5:38 PM
  • Thanks for the reply Karen.

    I was having problems where it was saved by the user.

    Sunday, April 7, 2019 5:40 PM