Link to home
Start Free TrialLog in
Avatar of QPR
QPRFlag for New Zealand

asked on

Is a field but is used like a type

I have taken a code snippet and am trying to mold it to my needs but am getting errors early on.
It should be a simple get file from A and save file to B process.
But I am getting these errors
'HubbleDocs.GetFile.copyService' is a 'field' but is used like a 'type'      
and
A field initializer cannot reference the non-static field, method, or property 'HubbleDocs.GetFile.fieldInfo'      

Here is the code in full, much appreciated if someone could get me over the line on this please

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;

namespace HubbleDocs
{
    public class GetFile
    {

        string webUrl = "http://localhost:1000";
        FileCopy.Copy copyService = new FileCopy.Copy();
        copyService.Url = webUrl +"/_vti_bin/copy.asmx";
         NetworkCredential m_credentials = new NetworkCredential(UserId, Pwd, Domain)
             copyService.Credentials = m_credentials;

        //Source and Destination Document URLs
         string sourceUrl = "http://localhost:1000/Shared Documents/Sample.doc";
         string destinationUrl = "C:\\Documents\\Sample.doc";

        //Variables for Reading metadata’s of a document
         FileCopy.FieldInformation fieldInfo = new FileCopy.FieldInformation();
         FileCopy.FieldInformation[] fieldInfoArray = { fieldInfo };
         FileCopy.CopyResult cResult1 = new FileCopy.CopyResult();
         FileCopy.CopyResult cResult2 = new FileCopy.CopyResult();
         FileCopy.CopyResult[] cResultArray = { cResult1, cResult2 };

        

        //Receive a Document Contents  into Byte array (filecontents)
         byte[] fileContent; // no need to initialize the GetItem takes care of that.
         copyService.GetItem(sourceUrl, out fieldInfoArray, out fileContents);

        //Create a new file and write contents to that document
         FileStream fStream = new FileStream(destinationUrl, FileMode.Create, FileAccess.ReadWrite);
        fStream.Write(fileContents, 0, fileContents.Length);
        fStream.Close();

    }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of QPR

ASKER

Perfect thanks. Stand by for more beginner questions :)