I need to know how can I use app path? I have a added Shockwave Flash Object control there in my program. However I have added AxShockwaveFlash1(swfla1) there in my form.
I have written code there in Form_Load event so that swfla1 will get flash file(.swf) to play.

Form_Load event code : Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
swfla1.Movie = ("D:\Documents and Settings\James\My Documents\Test project\Animation\Animation.swf")
End Sub

Swfla1 will get flash file (.swf) from ("D:\Documents and Settings\James\My Documents\Test project\Animation\Animation.swf") this location. As a result if user will install it there in another drive it will show error message or it will not work. So I want to know how can I use app path so solve this problem? Please help me.

Dani AI

Generated

Short answer: stop hard-coding the D: path and build the filename from the application or user folder at runtime, and always use path helpers (not string concatenation). ’s idea to use special folders and /’s suggestion to use the app’s startup location are both valid — which to use depends on whether the SWF is a user file (put it in My Documents or AppData) or a shipped file (put it next to the EXE). (learn.microsoft.com)

Practical pattern: decide "shipped" vs "user data", then build the path with Path.Combine and check File.Exists before assigning swfla1.Movie. Using My.Application.Info.DirectoryPath (or Application.StartupPath) avoids drive-specific hard-coding and keeps your paths portable. Example (VB.NET):

Dim swfPath = System.IO.Path.Combine(My.Application.Info.DirectoryPath, "Animation", "Animation.swf")
If Not System.IO.File.Exists(swfPath) Then
  swfPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Test project", "Animation", "Animation.swf")
End If

If System.IO.File.Exists(swfPath) Then
  swfla1.Movie = swfPath
Else
  ' log or show a clear error so the user can fix missing file
End If

Use Path.Combine rather than manual backslashes so you don’t accidentally create malformed paths. Also mark the SWF as project Content and set CopyToOutputDirectory (Copy if newer / Copy always) or include it in your installer so it lands next to the EXE on the target machine. (learn.microsoft.com)

Important caution: Flash/Shockwave is end-of-life (Adobe stopped support on 2020-12-31) and modern Windows/browsers block or remove Flash. If this app is being used today, consider converting the animation or using an emulator like Ruffle for playback instead of relying on the ActiveX Shockwave control. Test on target machines and add robust error handling so missing/blocked SWFs fail gracefully. ()

Recommended Answers

All 3 Replies

Environment.GetFolderPath() -function gives you the correct path. Function parameter is one of the Environment.SpecialFolder -enumeration values.

Dim PathStr As String

    PathStr = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
    ' Append "\" if missing
    If PathStr.Length > 0 AndAlso Not PathStr.EndsWith(Path.DirectorySeparatorChar) Then
      PathStr &= Path.DirectorySeparatorChar
    End If
    ' Append hard-coded subfolder and file name (or read it from a file, prompt user, or...)
    PathStr &= "Test project\Animation\Animation.swf"

The code above should give you:

PathStr = "D:\Documents and Settings\James\My Documents\Test project\Animation\Animation.swf"

and if you had Windows Vista/7 you should get:

PathStr = "C:\Users\James\My Documents\Test project\Animation\Animation.swf"

The point is to use Environment.GetFolderPath() -function, not to hard-code special folder names since they are different between Windows versions.

HTH

Hi,

Or you can use the application StartupPath.

'First , add reference to ShockWave Flash Object Library
'existed on the COM Tab . Paste the control on your form.
'Use the code below as follow : 
'Add your flashfile to the Bin folder

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        With FlashObj
            .Stop()
            .Movie = Application.StartupPath & "\nameofyourflashfile.swf"
            .Play()
        End With
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        FlashObj.Dispose()
        Application.Exit()
    End Sub


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

you can get the path by using this

Application.StartupPath & "Animation.swf"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.