1

When I manually copy and paste the file into the library, the event receiver ItemAdded runs normally.

But when the file is uploaded via web service it does not run.

Any ideas?

My code:

public string UploadFilePortal(string pathArquivo)
    {
        string docLibrary = "http://site/web/financeiro/";
        string libraryUrl = "ComprovantesPagamento";
        string retorno = String.Empty;
        string fileName = Path.GetFileName(pathArquivo);


        Utils.LogTextoCpvtes("Uploading file... " + pathArquivo +
                        DateTime.Now.ToString());


        WSCopy.Copy wsCopy = new WSCopy.Copy();

        wsCopy.Url = docLibrary + "_vti_bin/copy.asmx";
        wsCopy.Credentials = GetUserPortal();

        byte[] binaryFile = File.ReadAllBytes(pathArquivo);

        string pasta = @"/";


        // Valor Pagamento:
        WSCopy.FieldInformation fieldValor = new
                                        WSCopy.FieldInformation();
        fieldValor.DisplayName = "ValorPagamento";
        fieldValor.InternalName = "ValorPagamento";
        fieldValor.Type = WSCopy.FieldType.Currency;
        fieldValor.Value = "0";

        // Negocio:
        WSCopy.FieldInformation fieldNegocio = new
                                        WSCopy.FieldInformation();
        fieldNegocio.DisplayName = "Negocio";
        fieldNegocio.InternalName = "Negocio";
        fieldNegocio.Type = WSCopy.FieldType.Choice;
        fieldNegocio.Value = "OR";

        // IDDocRastreabilidade:
        WSCopy.FieldInformation fieldIdDocRastr = new
                                        WSCopy.FieldInformation();
        fieldIdDocRastr.DisplayName = "IDDocRastreabilidade";
        fieldIdDocRastr.InternalName = "IDDocRastreabilidade";
        fieldIdDocRastr.Type = WSCopy.FieldType.Number;
        fieldIdDocRastr.Value = "0";


        //WSCopy.FieldInformation[] fields = { fieldTitle };

        WSCopy.FieldInformation[] fields = { fieldValor, fieldNegocio, fieldIdDocRastr };

        string destiny = docLibrary +
                            libraryUrl +
                            @"/" +
                            fileName;

        string otherDestiny = fileName;

        string[] destinationUrl = { destiny };

        WSCopy.CopyResult resultTest = new WSCopy.CopyResult();
        WSCopy.CopyResult[] result = { resultTest };

        try
        {
            wsCopy.CopyIntoItems(otherDestiny, destinationUrl,
                                    fields, binaryFile, out result);

            if (result[0].ErrorCode != WSCopy.CopyErrorCode.Success)
            {
                //exception:
                throw new ImpossibleUploadFilePortalException(
                            "Not possible upload file: " +
                                result[0].ErrorCode.ToString() + " - " +
                                result[0].ErrorMessage);
            }

        }
        catch (Exception exc)
        {
            throw exc;
        }

        return retorno;
    }
  • Can you post your event receiver code? – Robert Lindgren Mar 6 '14 at 20:22
  • code posted @RobertLindgren – Douglas Mendes Mar 6 '14 at 20:29
  • Sorry, I was more interested in the ItemAdded code – Robert Lindgren Mar 6 '14 at 21:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.