Ответы пользователя по тегу .NET
  • Нужен хороший торрент-клиент, которым можно управлять из среды .NET?

    Iliapan
    @Iliapan
    А почему нельзя utorrent управлять через веб-интерфейс? На крайний случай…
    Ответ написан
  • Как в C# обрабатывать все необработанные исключения?

    Iliapan
    @Iliapan
    обращения к ним в try...catch блок
    Ответ написан
    Комментировать
  • Закладки Word

    Iliapan
    @Iliapan
    вообще обленились?

        To insert text in a range
    
    1. Specify a range at the beginning of a document and insert the text New Text.
    
    The following code example can be used in a document-level customization.
    
    object start = 0;
    
    object end = 0;
    
    Word.Range rng = this.Range(ref start, ref end);
    
    rng.Text = “New Text”;
    
    The following code example can be used in an application-level add-in. This code uses the active document.
    
    Word.Range rng = this.Application.ActiveDocument.Range(0, 0);
    
    rng.Text = “New Text”;
    
    2. Select the Range object, which has expanded from one character to the length of the inserted text.
    
    rng.Select();
    
        Replacing Text in a Range
    
    If the specified range contains text, all text in the range is replaced with the inserted text.
    
     1. Create a Range object that consists of the first 12 characters in the document.
    
    The following code example can be used in a document-level customization.
    
    object start = 0;
    
    object end = 12;
    
    Word.Range rng = this.Range(ref start, ref end);
    
    The following code example can be used in an application-level add-in. This code uses the active document.
    
    Word.Range rng = this.Application.ActiveDocument.Range(0, 12);
    
    2. Replace those characters with the string New Text.
    
    rng.Text = “New Text”;
    
    3. Select the range.
    
    rng.Select();
    
    Ответ написан
    5 комментариев
  • Аналог php функции strtr в .Net

    Iliapan
    @Iliapan
    Есть несколько вариантов, самый полезный для вас — через регекспы. Разберитесь с ними и потом это пригодится. Regex.Replace и далее уже как нафантазируете.
    Ответ написан
    Комментировать
  • Веб-сервис не хочет отдавать результат в JSON

    Iliapan
    @Iliapan
    Вот как мы это делаем — отправка запроса в json и обратно:

    With input
    .token = token
    .application_id = application_id
    .login = login
    .locale = locale
    End With
    '// сериализуем объект ClientInfo в формат нотации JSON

    Dim stream1 As New MemoryStream()
    Dim ser As New DataContractJsonSerializer(input.GetType)
    ser.WriteObject(stream1, input)
    stream1.Position = 0
    Dim sr As New StreamReader(stream1)
    Dim json As String = sr.ReadToEnd

    ' // создаем клиента
    Dim wc As WebClient = New WebClient()

    '// отправляем POST-запрос и получаем ответ
    Dim result() As Byte = wc.UploadData(wsdl, "POST", System.Text.Encoding.UTF8.GetBytes(json))

    Dim t As String = Encoding.UTF8.GetString(result)

    stream1.Close()

    Dim stream2 As New MemoryStream
    Dim sw As New StreamWriter(stream2)
    sw.Write(t)
    sw.Flush()
    stream2.Position = 0

    If t.Contains("error_detail") Then
    Dim myErr As New yaError
    Dim ser2 As New DataContractJsonSerializer(myErr.GetType)

    ' Deserialize the data and read it from the instance.
    myErr = CType(ser2.ReadObject(stream2), yaError)
    stream2.Close()
    Return myErr
    Else
    Dim ser2 As New DataContractJsonSerializer(reply.GetType)
    reply = ser2.ReadObject(stream2)
    Return reply
    End If
    Ответ написан