打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
ClickOnce部署(VB2010实例)

本文演示使用 ClickOnce 部署和更新应用程序,来自乐博网。

如果你想下载本文的源代码RAR压缩集合包  请访问
VB2010源代码集合包(芋头糕)    http://www.lob.cn/code/utility/2795.shtml 
特别感谢网友 芋头糕 将此资源提供乐博网分享 ,欢迎加入 40797788 的.Net超级qq群交流。

ClickOnce部署实例代码如下:


 'Copyright (c) Microsoft Corporation. All rights reserved.
Imports System.Deployment

Public Class MainForm

    Private WithEvents deployment As System.Deployment.Application.ApplicationDeployment

    Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If My.Application.IsNetworkDeployed Then
            AddHandler My.Application.Deployment.CheckForUpdateCompleted, AddressOf Me.CheckForUpdateCompleted
            AddHandler My.Application.Deployment.DownloadFileGroupCompleted, AddressOf Me.DownloadFilesCompleted
            AddHandler My.Application.Deployment.UpdateProgressChanged, AddressOf Me.ProgressChanged
            AddHandler My.Application.Deployment.UpdateCompleted, AddressOf Me.UpdateCompleted
        Else
            AppendContentLine(My.Resources.IsNotNetworkDeployed)
        End If
    End Sub

    Private Property Content() As String
        Get
            Return Me.ContentTextbox.Text
        End Get
        Set(ByVal value As String)
            Me.ContentTextbox.Text = value
        End Set
    End Property


    Private Sub CurrentDeploymentInfoButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CurrentDeploymentInfoButton.Click
        Content = String.Empty
        If My.Application.IsNetworkDeployed Then
            With My.Application.Deployment
                AppendContentLine('Application full name: ' & .UpdatedApplicationFullName)
                AppendContentLine('Current version: ' & .CurrentVersion.ToString())
                AppendContentLine('Update location: ' & .UpdateLocation.ToString())
                AppendContentLine('Last update check: ' & .TimeOfLastUpdateCheck.ToString())
            End With
        Else
            AppendContentLine(My.Resources.IsNotNetworkDeployed)
        End If
    End Sub


    Private Sub UpdateInfoButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdateInfoButton.Click
        Content = String.Empty
        If (My.Application.IsNetworkDeployed) Then
            With My.Application.Deployment
                Dim uci As System.Deployment.Application.UpdateCheckInfo = .CheckForDetailedUpdate()

                AppendContentLine('Update available: ' & uci.UpdateAvailable)

                If (Not (uci.UpdateAvailable)) Then
                    Exit Sub
                End If   '更多.net源代码 来自乐博网lob.cn

                AppendContentLine('Available version: ' & uci.AvailableVersion.ToString())
                AppendContentLine('Update required: ' & uci.IsUpdateRequired)
                AppendContentLine('Minimum required version: ' & uci.MinimumRequiredVersion.ToString())
                AppendContentLine('Update size: ' & uci.UpdateSizeBytes.ToString())
            End With
        Else
            AppendContentLine(My.Resources.IsNotNetworkDeployed)
        End If
    End Sub

    Private Sub DownloadButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DownloadButton.Click
        Content = String.Empty
        If My.Application.IsNetworkDeployed Then
            My.Application.Deployment.DownloadFileGroupAsync('Media')
            AppendContentLine('Downloading files...')
        Else
            AppendContentLine(My.Resources.IsNotNetworkDeployed)
        End If
    End Sub

    Private Sub UpdateButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdateButton.Click
        Content = String.Empty
        If My.Application.IsNetworkDeployed Then
            AppendContentLine('Updating application...')
            My.Application.Deployment.UpdateAsync()
        Else
            AppendContentLine(My.Resources.IsNotNetworkDeployed)
        End If
    End Sub

    Private Sub CheckForUpdateCompleted(ByVal sender As Object, ByVal e As System.Deployment.Application.CheckForUpdateCompletedEventArgs)
        If e.UpdateAvailable Then
            AppendContentLine('Update available.')
        Else
            AppendContentLine('No update available.')
        End If
    End Sub
    Private Sub DownloadFilesCompleted(ByVal sender As Object, ByVal e As System.Deployment.Application.DownloadFileGroupCompletedEventArgs)
        AppendContentLine('Download files complete.')
        My.Forms.PictureForm.ShowDialog()
    End Sub


    Private Sub UpdateCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
        AppendContentLine('Update complete. Restart the application to run the new version.')
    End Sub


    Private Sub ProgressChanged(ByVal sender As Object, ByVal e As System.Deployment.Application.DeploymentProgressChangedEventArgs)
        AppendContentLine(String.Format('({0}%) {1} of {2} bytes downloaded.', e.ProgressPercentage, e.BytesCompleted, e.BytesTotal))
    End Sub


    Private Sub AppendContentLine(ByVal str As String)
        Content += str & vbNewLine & vbNewLine
    End Sub

    Private Sub ViewSourceCodeToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ViewSourceCodeToolStripButton.Click
        My.Forms.ViewSourceForm.ShowDialog()
    End Sub

    Private Sub exitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles exitToolStripMenuItem.Click
        Me.Close()
    End Sub
End Class

请在这里输入栏目框的内容

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
Byte Array to String
VB.NET控件数组正确使用方法分析
vb.net利用SerialPort进行读取串口操作
VB.Net RS232串行通信AutoReceive的实例
vb.net发邮件源码
VB.net学习笔记(七)对象事件的定制
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服