Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 290

Re: Save InfoObject's files to disk (C#)

$
0
0

Unfortunately, the repository query that you list doesn't return any results on my system (I don't have admin. rights if that makes a difference).  Is there another way to get the path of the I/O servers?

 

What about using the CrystalDecisions.Enterprise.File.CopyTo() method?

 

The following gives me an error that reads "The best overloaded method match for 'CrystalDecisions.Enterprise.File.CopyTo(ref object)' has some invalid arguments":

 

# assumes query results...

CrystalDecisions.Enterprise.File file = infoObjects[1].Files[1];

 

# create a byte-array buffer the same size as the file

Byte[] buffer = new Byte[file.Size];

 

# copy contents to buffer

file.CopyTo(ref buffer);

 

# save buffer to a file

using (FileStream fileStream = new FileStream(filePath, FileMode.Create))

{

  fileStream.WriteByte(buffer);

}

 

** edit 1 **

 

Got the code to work:

 

# assumes query results...

CrystalDecisions.Enterprise.File file = infoObjects[1].Files[1];

 

# specify (dummy) path; cast as object

Object destination = (Object)"C:\\Users\\USERNAME\\Desktop\\Foobar.rpt";

 

# copy the file to the destination

file.CopyTo(ref destination);

 

** edit 2 **

 

Another CopyTo() approach:

 

using (FileStream fileStream = new FileStream(filePath, FileMode.Create))

{

    # create properly sized byte array; cast as object

    Object bufferObject = (Object)new Byte[file.Size];

 

    # copy the file to the buffer object

    file.CopyTo(ref bufferObject);

 

    # cast the object as a byte array

    Byte[] buffer = (Byte[])bufferObject;

 

    # save byte array to file

    fileStream.Write(buffer,0,buffer.Length);

 

}


Viewing all articles
Browse latest Browse all 290

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>