Esempio n. 1
0
        /// <summary>
        /// Putfile chiamato per l'inserimento in SharePoint del documento.
        /// </summary>
        /// <param name="fileforcontenct">Oggetto dal quale prendo i byte del File</param>
        /// <param name="schedaDocBase">Scheda documento, usata per i parametri in SharePoint</param>
        /// <param name="_infoutente">Info Utente</param>
        /// <param name="fileRequest">Oggetto utile alla get del nome file e del Path</param>
        /// <param name="extention">Estensione del file da inserire nel documentale (es:doc)</param>
        /// <returns>True false a seconda dell'esito del PUT, non uso Try catch per far tornare l'errore originale</returns>
        public static bool PutFileInSP(ref DocsPaVO.documento.FileDocumento fileforcontenct,
                                       ref SchedaDocumento schedaDocBase, DocsPaVO.utente.InfoUtente _infoutente,
                                       ref DocsPaVO.documento.FileRequest fileRequest, string extention)
        {
            string sRemoteFileURL = null;
            string sSPURL         = GetServerRoot();

            //Istanzio il service
            SPCopy.Copy sp2010VmCopyService2Put = new SPCopy.Copy();
            //Setto le credenziali con le mie prese da db
            sp2010VmCopyService2Put.Credentials = GetCredentialSP();
            //eeeeeee
            //sp2010VmCopyService2Put.Url = string.Format("{0}/{1}", GetServerProtocollo() + GetServerRootnosites(), "_vti_bin/copy.asmx");
            sp2010VmCopyService2Put.Url =
                string.Format("{0}{1}/{2}/{3}", GetServerProtocollo(), GetServerRootnosites(), GetLibraryRoot(DateTime.Now.Year.ToString(), _infoutente.codWorkingApplication).Replace(@"/", "\\").ToUpper(), "_vti_bin/copy.asmx");

            //Nome file
            sRemoteFileURL = string.Format("{0}_{1}.{2}", _infoutente.codWorkingApplication, fileRequest.versionId, extention);
            //Url di destinazione sotto SP per la scrittura del file
            string[] destinationUrls = { Uri.EscapeUriString(GetServerProtocollo() + fileRequest.path) };
            //Faccio la Get della UO da passare nei Metadati
            DocsPaDB.Query_DocsPAWS.Utenti utentiDb = new DocsPaDB.Query_DocsPAWS.Utenti();
            DocsPaVO.utente.Ruolo          ruolo    = utentiDb.GetRuolo(_infoutente.idCorrGlobali, false);
            schedaDocBase.creatoreDocumento.uo_codiceCorrGlobali = ruolo.uo.codice;
            //Imposto i metadati.
            //correzione sabrina -- tutto l'oggetto fileRequest
            SPCopy.FieldInformation[] myFieldInfoArray = ImpostaMetaDati(ref schedaDocBase, _infoutente, fileRequest);

            //SPCopy.FieldInformation[] myFieldInfoArray = ImpostaMetaDati(ref schedaDocBase, _infoutente, fileRequest.version);
            SPCopy.CopyResult[] result;
            //Put del file sotto Sharepoint e sotto la sitecollection corretta
            sp2010VmCopyService2Put.CopyIntoItems(sRemoteFileURL, destinationUrls, myFieldInfoArray, fileforcontenct.content, out result);
            //Gestione errori:
            if (result[0].ErrorCode != SPCopy.CopyErrorCode.Success)
            {
                Console.WriteLine("Error occured during document upload process.");
                throw new Exception("Error Occured!" + result[0].ErrorCode);
            }

            //metadati null
            SPCopy.FieldInformation   myFieldInfo          = new SPCopy.FieldInformation();
            SPCopy.FieldInformation[] myFieldInfoArrayNull = { myFieldInfo };
            byte[] myByteArray;
            //Faccio la Get solo ed esclusivamente per valorizzare il nuovo contenct[] e il suo lenght.
            uint myGetUint = sp2010VmCopyService2Put.GetItem(destinationUrls[0], out myFieldInfoArrayNull, out myByteArray);

            //valorizzo.
            if (myByteArray == null || myByteArray.Length == 0)
            {
                return(false);
            }
            fileforcontenct.content = myByteArray;
            fileforcontenct.length  = myByteArray.Length;
            //Ok torno.
            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Getfile chiamato per il Get da SharePoint del documento.
        /// </summary>
        /// <param name="filename">Nome del file da concatenare alla URL del server.</param>
        /// <param name="sitecollectionurl">Parametro che conterrà il nome della site collection (es: 2012_DOCSPA)</param>
        /// <returns>Il file richiesto a Sharepoint</returns>
        public static byte[] GetFileFromSP(string filename, string sitecollectionurl)
        {
            //Get root
            string sSPURL = GetServerRoot();

            //istanzio il service
            SPCopy.Copy sp2010VmCopyService2Get = new SPCopy.Copy();
            //Do le credenziali
            sp2010VmCopyService2Get.Credentials = GetCredentialSP();
            //Istanzio i metadato vuoti
            SPCopy.FieldInformation   myFieldInfo      = new SPCopy.FieldInformation();
            SPCopy.FieldInformation[] myFieldInfoArray = { myFieldInfo };
            byte[] myByteArray;
            //Get del documento da Sharepoint
            sp2010VmCopyService2Get.Url = string.Format("{0}/{1}", GetServerProtocollo() + sSPURL, sitecollectionurl + "/_vti_bin/copy.asmx");
            uint myGetUint = sp2010VmCopyService2Get.GetItem(GetServerProtocollo() + filename, out myFieldInfoArray, out myByteArray);

            //ritorno file
            return(myByteArray);
        }
Esempio n. 3
0
        //*************************//
        //Upload Sharepoint Document
        //*************************//
        private void UploadFileToSharePoint(HttpPostedFileBase FileToUpload, String[] SharePointPath)
        {
            //1. Create the Copy service
                SPCopy.Copy copyService = new SPCopy.Copy();
                copyService.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;

                //2. Initialize the Copy result
                SPCopy.CopyResult cResult1 = new SPCopy.CopyResult();
                SPCopy.CopyResult cResult2 = new SPCopy.CopyResult();
                SPCopy.CopyResult[] cResultArray = { cResult1, cResult2 };

                //3. Create the document attributes
                SPCopy.FieldInformation fFiledInfo = new SPCopy.FieldInformation();
                fFiledInfo.DisplayName = "Description";
                fFiledInfo.Type = SPCopy.FieldType.Text;
                fFiledInfo.Value = "Ticket";
                SPCopy.FieldInformation[] fFiledInfoArray = { fFiledInfo };

                //4. create the file stream that will be sent
                Stream strm = FileToUpload.InputStream;
                byte[] fileContents = new Byte[strm.Length];
                byte[] r = new Byte[strm.Length];
                int ia = strm.Read(fileContents, 0, Convert.ToInt32(strm.Length));
                strm.Close();

            try {

                uint copyresult = copyService.CopyIntoItems(FileToUpload.FileName, SharePointPath, fFiledInfoArray, fileContents, out cResultArray);

                if (copyresult == 0)
                {
                    int idx = 0;
                    String copy_results;
                    foreach (SPCopy.CopyResult myCopyResult in cResultArray)
                    {
                        string opString = (idx + 1).ToString();
                        if (cResultArray[idx].ErrorMessage == null)
                        {
                            copy_results = ("Copy operation " + opString +
                                "completed.\r\n" + "Destination: " +
                                cResultArray[idx].DestinationUrl);
                        }
                        else
                        {
                            copy_results = "Copy operation " + opString +
                                " failed.\r\n" + "Error: " +
                                cResultArray[idx].ErrorMessage + "\r\n" +
                                "Code: " + cResultArray[idx].ErrorCode;
                        }
                        idx++;
                    }
                }
            }
            catch (Exception ex)
            {
                int idx = 0;
                string copy_results;
                foreach (SPCopy.CopyResult myCopyResult in cResultArray)
                {
                    idx++;
                    if (myCopyResult.DestinationUrl == null)
                    {
                        string idxString = idx.ToString();
                        copy_results = "Copy operation " + idxString +
                            " failed.\r\n" + "Description: " + ex.Message +
                            "Exception";
                    }
                }
            }
        }
Esempio n. 4
0
        ///// <summary>
        ///// Imposta i metadati da associare al documento in SharePoint, e sono:
        ///// DocNumber,segnatura,VersionId,AOO,UO,Utente,IdentificativoDocPrincipale.
        ///// </summary>
        ///// <param name="schedaDocPerMetadati">Scheda documeto passata già in Put</param>
        ///// <param name="_infoutente">Info Utente per reperire dati anagrafici (Utente, UO ecc)</param>
        ///// <param name="version">Versione del Documento</param>
        ///// <returns>FieldInformation[] da passare al server in fase di put.</returns>
        //private static SPCopy.FieldInformation[] ImpostaMetaDati(ref SchedaDocumento schedaDocPerMetadati,
        //                                                            DocsPaVO.utente.InfoUtente _infoutente, string version)
        //{
        //    // DocNumber (utilizzato per l’identificazione del documento);
        //    SPCopy.FieldInformation infoDocNumber = new SPCopy.FieldInformation();
        //    infoDocNumber.DisplayName = "DocNumber";
        //    infoDocNumber.InternalName = "DocNumber";
        //    infoDocNumber.Type = SPCopy.FieldType.Text;
        //    infoDocNumber.Value = (schedaDocPerMetadati.docNumber == null) ? "" : schedaDocPerMetadati.docNumber;

        //    //- segnatura (per l’identificazione del documento come protocollo; tale attributo sarà valorizzato unicamente per i documenti principali);
        //    SPCopy.FieldInformation infoSegnatura = new SPCopy.FieldInformation();
        //    infoSegnatura.DisplayName = "Segnatura";
        //    infoSegnatura.InternalName = "Segnatura";
        //    infoSegnatura.Type = SPCopy.FieldType.Text;
        //    infoSegnatura.Value = (schedaDocPerMetadati.protocollo == null) ? "" : schedaDocPerMetadati.protocollo.segnatura;

        //    //- VersionId (utilizzato per l’identificazione univoca di una specifica versione del documento);
        //    SPCopy.FieldInformation infoVersionId = new SPCopy.FieldInformation();
        //    infoVersionId.DisplayName = "VersionId";
        //    infoVersionId.InternalName = "VersionId";
        //    infoVersionId.Type = SPCopy.FieldType.Text;
        //    infoVersionId.Value = (version == null) ? "" : version;

        //    //- AOO (Area Organizzativa Omogenea),
        //    SPCopy.FieldInformation infoAOO = new SPCopy.FieldInformation();
        //    infoAOO.DisplayName = "AOO";
        //    infoAOO.InternalName = "AOO";
        //    infoAOO.Type = SPCopy.FieldType.Text;
        //    infoAOO.Value = (schedaDocPerMetadati.registro == null) ? "" : schedaDocPerMetadati.registro.codRegistro;

        //    //- UO (Unità Organizzativa),
        //    SPCopy.FieldInformation infoUO = new SPCopy.FieldInformation();
        //    infoUO.DisplayName = "UO";
        //    infoUO.InternalName = "UO";
        //    infoUO.Type = SPCopy.FieldType.Text;
        //    infoUO.Value = (schedaDocPerMetadati.creatoreDocumento == null) ? "" : schedaDocPerMetadati.creatoreDocumento.uo_codiceCorrGlobali;
        //    //- Utente (SP_Username creatore documento)
        //    SPCopy.FieldInformation infoUtente = new SPCopy.FieldInformation();
        //    infoUtente.DisplayName = "Utente";
        //    infoUtente.InternalName = "Utente";
        //    infoUtente.Type = SPCopy.FieldType.Text;
        //    infoUtente.Value = (_infoutente.userId == null) ? "" : _infoutente.userId;

        //    SPCopy.FieldInformation infoIdentificativoDocPrincipale = new SPCopy.FieldInformation();
        //    if ((schedaDocPerMetadati.documentoPrincipale != null) && schedaDocPerMetadati.documentoPrincipale.docNumber != "")
        //    {
        //        //- IdentificativoDocPrincipale (valorizzato unicamente per gli allegati al fine di avere anche su
        //        // SharePoint evidenza del fatto che un documento ha senso di esistere solo in relazione ad altri documenti).
        //        infoIdentificativoDocPrincipale.DisplayName = "IdentificativoDocumentoPrincipale";
        //        infoIdentificativoDocPrincipale.InternalName = "IdentificativoDocumentoPrincipale";
        //        infoIdentificativoDocPrincipale.Type = SPCopy.FieldType.Text;
        //        infoIdentificativoDocPrincipale.Value = schedaDocPerMetadati.documentoPrincipale.docNumber;
        //    }

        //    SPCopy.FieldInformation[] containerMeta = { infoDocNumber, infoVersionId, infoSegnatura, infoAOO, infoUO, infoUtente, infoIdentificativoDocPrincipale };

        //    return containerMeta;
        //}



        /// <summary>
        /// Imposta i metadati da associare al documento in SharePoint, e sono:
        /// DocNumber,segnatura,VersionId,VersionLabel,AOO,UO,Utente,IdentificativoDocPrincipale.
        /// </summary>
        /// <param name="schedaDocPerMetadati">Scheda documeto passata già in Put</param>
        /// <param name="_infoutente">Info Utente per reperire dati anagrafici (Utente, UO ecc)</param>
        /// <param name="fileReq">Versione del Documento</param>
        /// <returns>FieldInformation[] da passare al server in fase di put.</returns>
        private static SPCopy.FieldInformation[] ImpostaMetaDati(ref SchedaDocumento schedaDocPerMetadati,
                                                                 DocsPaVO.utente.InfoUtente _infoutente, FileRequest fileReq)
        {
            // DocNumber (utilizzato per l’identificazione del documento);
            SPCopy.FieldInformation infoDocNumber = new SPCopy.FieldInformation();
            infoDocNumber.DisplayName  = "DocNumber";
            infoDocNumber.InternalName = "DocNumber";
            infoDocNumber.Type         = SPCopy.FieldType.Text;
            infoDocNumber.Value        = (schedaDocPerMetadati.docNumber == null) ? "" : schedaDocPerMetadati.docNumber;

            //- segnatura (per l’identificazione del documento come protocollo; tale attributo sarà valorizzato unicamente per i documenti principali);
            SPCopy.FieldInformation infoSegnatura = new SPCopy.FieldInformation();
            infoSegnatura.DisplayName  = "Segnatura";
            infoSegnatura.InternalName = "Segnatura";
            infoSegnatura.Type         = SPCopy.FieldType.Text;
            infoSegnatura.Value        = (schedaDocPerMetadati.protocollo == null) ? "" : schedaDocPerMetadati.protocollo.segnatura;

            //- VersionId (utilizzato per l’identificazione univoca di una specifica versione del documento);
            SPCopy.FieldInformation infoVersionId = new SPCopy.FieldInformation();
            infoVersionId.DisplayName  = "VersionId";
            infoVersionId.InternalName = "VersionId";
            infoVersionId.Type         = SPCopy.FieldType.Text;
            infoVersionId.Value        = (fileReq.versionId == null) ? "" : fileReq.versionId;

            //sabrina
            //- VersionLabel (utilizzato per l’identificazione univoca di una specifica versione del documento);
            SPCopy.FieldInformation infoVersionLabel = new SPCopy.FieldInformation();
            infoVersionLabel.DisplayName  = "VersionLabel";
            infoVersionLabel.InternalName = "VersionLabel";
            infoVersionLabel.Type         = SPCopy.FieldType.Text;
            infoVersionLabel.Value        = (fileReq.versionLabel == null) ? "" : fileReq.versionLabel;

            //- AOO (Area Organizzativa Omogenea),
            SPCopy.FieldInformation infoAOO = new SPCopy.FieldInformation();
            infoAOO.DisplayName  = "AOO";
            infoAOO.InternalName = "AOO";
            infoAOO.Type         = SPCopy.FieldType.Text;
            infoAOO.Value        = (schedaDocPerMetadati.registro == null) ? "" : schedaDocPerMetadati.registro.codRegistro;

            //- UO (Unità Organizzativa),
            SPCopy.FieldInformation infoUO = new SPCopy.FieldInformation();
            infoUO.DisplayName  = "UO";
            infoUO.InternalName = "UO";
            infoUO.Type         = SPCopy.FieldType.Text;
            infoUO.Value        = (schedaDocPerMetadati.creatoreDocumento == null) ? "" : schedaDocPerMetadati.creatoreDocumento.uo_codiceCorrGlobali;
            //- Utente (SP_Username creatore documento)
            SPCopy.FieldInformation infoUtente = new SPCopy.FieldInformation();
            infoUtente.DisplayName  = "Utente";
            infoUtente.InternalName = "Utente";
            infoUtente.Type         = SPCopy.FieldType.Text;
            infoUtente.Value        = (_infoutente.userId == null) ? "" : _infoutente.userId;

            SPCopy.FieldInformation infoIdentificativoDocPrincipale = new SPCopy.FieldInformation();
            if ((schedaDocPerMetadati.documentoPrincipale != null) && schedaDocPerMetadati.documentoPrincipale.docNumber != "")
            {
                //- IdentificativoDocPrincipale (valorizzato unicamente per gli allegati al fine di avere anche su
                // SharePoint evidenza del fatto che un documento ha senso di esistere solo in relazione ad altri documenti).
                infoIdentificativoDocPrincipale.DisplayName  = "IdentificativoDocumentoPrincipale";
                infoIdentificativoDocPrincipale.InternalName = "IdentificativoDocumentoPrincipale";
                infoIdentificativoDocPrincipale.Type         = SPCopy.FieldType.Text;
                infoIdentificativoDocPrincipale.Value        = schedaDocPerMetadati.documentoPrincipale.docNumber;
            }

            SPCopy.FieldInformation[] containerMeta = { infoDocNumber, infoVersionId, infoVersionLabel, infoSegnatura, infoAOO, infoUO, infoUtente, infoIdentificativoDocPrincipale };

            return(containerMeta);
        }