الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مساعدة بخصوص web service

بدأه I_s في 18 يونيو 2010 · 1 رد · 531 مشاهدة · في ASP.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله وبركاته

الاخوة الكرام اعضاء المنتدى

ارجو منكم المساعدة في عمل treeview يتم ملئه بالمجلدات الموجودة في مسار معين على السيرفر حيث يملأ تلقائيا بالمجلدات والمجلداتلفرعية منها وهكذا

لكن ارغب في عمل هذا باستخدام web service لان انا بشتغل الشغل ده ب silverlight وعشان تظهر النتيجة لازم عملية ملأ الشجلرة تكون على ا اسيرفر من خلال ويب سيرفس عادية او wcf

لذا ارجو منكم المساعدة

مش مهم تتعمل silverlight ممكن تبقى صفحة عادية بس مربوطة ب web service او حد يدلي على الفكرة او يديني function بس

ارجو المساعدة العاجلة

#2

الاخوة الكرام انا عملت كود لكن مش بينفذ ولا بيطلع ايرور

معنى كدة ان الخطأ في اللوجيك بتاع البرمجة ومش قادرة اوصل الخطأ فين

فياريت ممن لديه الخبرة انه يساعدني

الكود كالتالي:

Mainpage.XAML

<UserControl x:Class="testtree.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400" xmlns:my="clr-namespace:Liquid;assembly=Liquid.TreeView" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">

    <Grid x:Name="LayoutRoot" Background="White">
        <my:Tree EnableLines="True" Height="276" Margin="44,0,204,12" Name="testTree" VerticalAlignment="Bottom" Populate="Tree_Populate" />
    </Grid>
</UserControl>

ManiPage.Xaml.vb

Imports System
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports System.IO
Imports System.Linq
Imports System.Text
Imports System.Windows.Threading
Imports System.Windows
Imports System.Windows.Browser
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes
Imports System.Xml
Imports Liquid
Imports Liquid.Components
Imports testtree.ServiceReference1.UploaderFileNode


Partial Public Class MainPage
    Inherits UserControl
    Private _autoSelectNodeID As String = String.Empty
    Dim client As New ServiceReference1.Service1Client

    Public Sub New()
        InitializeComponent()
        testTree.BuildRoot()

    End Sub

    Private Sub Tree_Populate(ByVal sender As Object, ByVal e As TreeEventArgs)
        If TypeOf sender Is Tree Then
            ' We are populating the root nodes collection
            DirectCast(sender, Tree).Nodes.Add(New Node("documents/", "My Documents", True, "images/folder.png", "images/folderOpen.png", True))
        Else
            ' Otherwise we are populating a node, add a node to say we are working
            DirectCast(sender, Node).IsBusy = True
            ' Call the webservice
            BeginGetNodes(DirectCast(sender, Node))
        End If
    End Sub

    Private Sub BeginGetNodes(ByVal node As Node)
        ' GetFilesInFolder
        ' Dim helper As New Comms(New Uri(_website & "FileUploadService.asmx/GetFoldersInFolder"), "POST", False, New KeyValuePair(Of String, String)("folder", HttpUtility.UrlEncode(node.ID)))
        AddHandler client.GetFoldersInFolderCompleted, New EventHandler(Of testtree.ServiceReference1.GetFoldersInFolderCompletedEventArgs)(AddressOf EndGetNodes)
        client.GetFilesInFolderAsync(node.ID)
    End Sub

    Private Sub EndGetNodes(ByVal Sender As Object, ByVal e As testtree.ServiceReference1.GetFoldersInFolderCompletedEventArgs)
        'Dim n As New Node(
        Dim files As New ObservableCollection(Of ServiceReference1.UploaderFileNode)
        files = e.Result
        Dim n As Node

        For i = 0 To files.Count
            n = New Node(files(i).ID, files(i).ID, files(i).Param > 0)
            PopulateChildren(n, files(i).Param)
        Next
    End Sub

    Private Sub PopulateChildren(ByVal workingNode As Node, ByVal populateNode As integer)
        Dim id As String = String.Empty
        Dim param As Integer = 0
        Dim icon As String = String.Empty
        Dim iconExpanded As String = String.Empty
        If populateNode Then
            workingNode.BulkUpdateBegin()
        Else
            '  items.Clear()
        End If
        id = workingNode.ID
        param = populateNode
        If id.EndsWith("/") Then
            ' Indicates this node is a folder
            workingNode.Nodes.Add(New Node(id, GetTitle(id), (param > 0), "images/folder.png", "images/folderOpen.png", True))
        End If
        If populateNode Then
            workingNode.BulkUpdateEnd()
            workingNode.IsBusy = False
        Else
            '  items.Add(fileItems)
        End If
    End Sub

    Private Function GetTitle(ByVal filename As String) As String
        Dim split As String() = filename.TrimEnd("/"c).Split("/"c)
        Dim title As String = filename

        If split.Length > 0 Then
            title = split(split.Length - 1)
        End If

        Return title
    End Function

    Private Function GetIcon(ByVal filename As String) As String
        Dim split As String() = filename.Split("."c)
        Dim extension As String = String.Empty

        If split.Length > 0 Then
            extension = split(split.Length - 1).ToLower()
        End If

        If extension <> "pdf" AndAlso extension <> "xls" AndAlso extension <> "doc" AndAlso extension <> "gif" AndAlso extension <> "mp3" AndAlso extension <> "ascx" AndAlso extension <> "asmx" AndAlso extension <> "aspx" AndAlso extension <> "avi" AndAlso extension <> "config" AndAlso extension <> "cs" AndAlso extension <> "css" AndAlso extension <> "htm" AndAlso extension <> "html" AndAlso extension <> "jpg" AndAlso extension <> "js" AndAlso extension <> "mp4" AndAlso extension <> "png" AndAlso extension <> "txt" AndAlso extension <> "xaml" AndAlso extension <> "xml" AndAlso extension <> "zip" Then
            extension = "unknown"
        End If

        Return extension & ".png"
    End Function



End Class

service1.svc

Imports System.ServiceModel
Imports System.ServiceModel.Activation
Imports System.Collections
Imports System.IO
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Text.RegularExpressions
Imports System.Collections.Generic

<ServiceContract()> <AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)> Public Class Service1
    <OperationContract()> _
    Public Function GetInFolder(ByVal folder As String) As List(Of UploaderFileNode)
        Dim nodes As New List(Of UploaderFileNode)()
        Dim files As String()
        Dim path As String = AppDomain.CurrentDomain.BaseDirectory & "\data" & folder
        Dim basePath As String = AppDomain.CurrentDomain.BaseDirectory & "\data"
        Dim id As String
        Dim childCount As Integer = 0
        ' If folder.StartsWith("documents/") OrElse folder.StartsWith("images/") Then
        files = Directory.GetDirectories(path)
        For Each s As String In files
            childCount = Directory.GetDirectories(s).Length
            id = s.Replace(basePath, "").Replace("\", "/").TrimStart("/"c) & "/"
            nodes.Add(New UploaderFileNode(id, childCount))
        Next
        files = Directory.GetFiles(path)
        For Each s As String In files
            id = s.Replace(basePath, "").Replace("\", "/").TrimStart("/"c)
            nodes.Add(New UploaderFileNode(id, 0))
        Next
        'End If
        Return nodes
    End Function

    <OperationContract()> _
    Public Function GetFoldersInFolder(ByVal folder As String) As List(Of UploaderFileNode)
        Dim nodes As New List(Of UploaderFileNode)()
        Dim files As String()
        Dim path As String = AppDomain.CurrentDomain.BaseDirectory & "\data\" & folder
        Dim basePath As String = AppDomain.CurrentDomain.BaseDirectory() & "\data\"
        Dim id As String
        Dim childCount As Integer = 0

        '  If folder.StartsWith("documents/") Then
        files = Directory.GetDirectories(path)

        For Each s As String In files
            childCount = Directory.GetDirectories(s).Length

            id = s.Replace(basePath, "").Replace("\", "/").TrimStart("/"c) & "/"
            nodes.Add(New UploaderFileNode(id, childCount))
        Next
        'End If
        Return nodes
    End Function

    <OperationContract()> _
    Public Function GetFilesInFolder(ByVal folder As String) As List(Of UploaderFileNode)
        Dim nodes As New List(Of UploaderFileNode)()
        Dim files As String()
        Dim path As String = AppDomain.CurrentDomain.BaseDirectory & "\data\" & folder
        Dim basePath As String = AppDomain.CurrentDomain.BaseDirectory & "\data\"
        Dim temp As FileInfo
        Dim id As String
        nodes.AddRange(GetFoldersInFolder(folder))
        If folder.StartsWith("documents/") Then
            files = Directory.GetFiles(path)
            For Each s As String In files
                id = s.Replace(basePath, "").Replace("\", "/").TrimStart("/"c)
                temp = New FileInfo(s)
                nodes.Add(New UploaderFileNode(id, CInt(temp.Length)))
            Next
        End If
        Return nodes
    End Function
End Class

Public Class UploaderFileNode
#Region "Private Properties"

    Private _id As String = String.Empty
    Private _param As Integer = 0

#End Region

#Region "Public Properties"

    Public Property ID() As String
        Get
            Return _id
        End Get
        Set(ByVal value As String)
            _id = value
        End Set
    End Property

    Public Property Param() As Integer
        Get
            Return _param
        End Get
        Set(ByVal value As Integer)
            _param = value
        End Set
    End Property

    Public ReadOnly Property HasChildren() As Boolean
        Get
            Return _param > 0
        End Get
    End Property

#End Region

#Region "Constructor"

    Public Sub New()
    End Sub

    Public Sub New(ByVal id As String, ByVal param As Integer)
        _id = id
        _param = param
    End Sub

#End Region
End Class

تم تعديل هذه المشاركة بواسطة I_s في 22 يونيو 2010 في 00:43

مواضيع مشابهة