Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - VB 2008 MoveFile e dispose
Forum - C# / VB.NET - VB 2008 MoveFile e dispose

Avatar
donatella72 (Normal User)
Newbie


Messaggi: 1
Iscritto: 22/04/2022

Segnala al moderatore
Postato alle 15:17
Venerdì, 22/04/2022
Salve,
   sono nuova del forum non so se ho postato nel posto giusto.
Devo spostare file xls dalla directory di un server in un'altra directory di un altro server. Vorrei usare dispose()
per le risorse da rilasciare, perché il file sembra rimanere in uso, ma non so come.
Sono un principiante. Questo il mio codice:

Codice sorgente - presumibilmente VB.NET

  1. ' Microsoft SQL Server Integration Services Script Task
  2. ' Write scripts using Microsoft Visual Basic 2008.
  3. ' The ScriptMain is the entry point class of the script.
  4.  
  5. Imports System
  6. Imports System.Data
  7. Imports System.Math
  8. Imports Microsoft.SqlServer.Dts.Runtime
  9. Imports System.IO
  10.  
  11. <System.AddIn.AddIn("ScriptMain", Version:="1.0", Publisher:="", Description:="")> _
  12. <System.CLSCompliantAttribute(False)> _
  13. Partial Public Class ScriptMain
  14.     Inherits Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
  15.  
  16.     Enum ScriptResults
  17.         Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
  18.         Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
  19.     End Enum
  20.  
  21.     ' The execution engine calls this method when the task executes.
  22.     ' To access the object model, use the Dts property. Connections, variables, events,
  23.     ' and logging features are available as members of the Dts property as shown in the following examples.
  24.     '
  25.     ' To reference a variable, call Dts.Variables("MyCaseSensitiveVariableName").Value
  26.     ' To post a log entry, call Dts.Log("This is my log text", 999, Nothing)
  27.     ' To fire an event, call Dts.Events.FireInformation(99, "test", "hit the help message", "", 0, True)
  28.     '
  29.     ' To use the connections collection use something like the following:
  30.     ' ConnectionManager cm = Dts.Connections.Add("OLEDB")
  31.     ' cm.ConnectionString = "Data Source=localhost;Initial Catalog=AdventureWorks;Provider=SQLNCLI10;Integrated Security=SSPI;Auto Translate=False;"
  32.     '
  33.     ' Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
  34.     '
  35.     ' To open Help, press F1.
  36.  
  37.     Dim NomefileDestinazione, NomeFilesorgente As String
  38.  
  39.  
  40.     Public Sub Main()
  41.         '
  42.         ' Add your code here
  43.         '
  44.         NomeFilesorgente = "\\servername1\DirectoryName\testing.xls"
  45.         NomefileDestinazione = "\\servername2\DirectoryName\" & Dts.Variables("NomeFilexls").Value.ToString & "_Parte" & Dts.Variables("j").Value.ToString & ".xls"
  46.         My.Computer.FileSystem.MoveFile(NomeFilesorgente, NomefileDestinazione, True)
  47.         Dts.Variables("j").Value = CInt(Dts.Variables("j").Value.ToString) + 1
  48.  
  49.         Dts.TaskResult = ScriptResults.Success
  50.     End Sub
  51.  
  52. End Class



Uso questo codice in un task SSIS ed esattamente nel task For Loop Container .

Vi ringrazio per l'aiuto.

Ultima modifica effettuata da Thejuster il 22/04/2022 alle 16:27
PM Quote
Avatar
Thejuster (Admin)
Guru^2


Messaggi: 2305
Iscritto: 04/05/2008

Segnala al moderatore
Postato alle 16:34
Venerdì, 22/04/2022
Ciao,
usa sempre il tag code per il codice altrimenti diventa incompresibile.


Codice sorgente - presumibilmente Plain Text

  1. NomeFilesorgente = "\\servername1\DirectoryName\testing.xls"
  2.         NomefileDestinazione = "\\servername2\DirectoryName\" & Dts.Variables("NomeFilexls").Value.ToString & "_Parte" & Dts.Variables("j").Value.ToString & ".xls"
  3.         My.Computer.FileSystem.MoveFile(NomeFilesorgente, NomefileDestinazione, True)




NomeFilesorgente = "\\servername1\DirectoryName\testing.xls"

Devi specificare un indirizzo fisico di dove è siutato il file.

un esempio è:
Copia da C:\testo.txt  in  \\ufficio\cartella\testo.txt

nel tuo esempio e come se un terzo computer chiederebbe di copiare un file dal 1 terminale al secondo terminale.



https://mire.forumfree.it/ - Mire Engine
C# UI Designer
PM Quote