Retrieving, Editing and Saving the contents of embedded WiKi files.

John

Using the information in response to post 4902 I was able to create an AyaFileList of all the embedded files from a selected client’s WiKi page. However, the list created with the AyaFileList method “GetList(Guid)” is only returning the AyaFileListInfo Structure data. This information does not contain a Guid ID for the file that I want to access.

Without the desired files ID how do I read embedded files content?

If I assume I can get a files ID and gain access to the file object using the AyaFile Class; how should I process to read and write to the file?

The “GetContent” method of the AyaFile Class has the type “MemoryStream”. Do I need to create a MemoryStream object to work with the content of embedded WiKi page files?

Your help is appreciated.

GLENN_OVIS (11/27/2009)John

Using the information in response to post 4902 I was able to create an AyaFileList of all the embedded files from a selected client’s WiKi page. However, the list created with the AyaFileList method “GetList(Guid)” is only returning the AyaFileListInfo Structure data. This information does not contain a Guid ID for the file that I want to access.

Without the desired files ID how do I read embedded files content?

If I assume I can get a files ID and gain access to the file object using the AyaFile Class; how should I process to read and write to the file?

The “GetContent” method of the AyaFile Class has the type “MemoryStream”. Do I need to create a MemoryStream object to work with the content of embedded WiKi page files?

Your help is appreciated.

Hi Glen, AyaFile object is not a direct store you can read and write to like a disk, it’s purpose is only to retrieve the file from the database and store it to the database. You can modify the file in memory in your app using a memorystream or you can work with it on disk in your app or others using the static method to write the file to disk. In either case you then need to use the SetContent method (and save of course) to update the file to database.

AyaFileListInfo contains a field called: LT_O_AyaFile which is of type GridNameValueCellItem which contains both a Display value for grids and an internal ID Value Guid field for doing things with it. See the API reference http://api.ayanova.com/ scroll down the left to GridNameValueCellItem it’s commonly used for all read only lists in AyaNova api that are displayed in grids.

The AyaFile ID is in the Value field of the LT_O_AyaFile field.

If you want to work with an AyaFile on disk you can save it to disk using the AyaFile static method GetAndWriteFileToDisk also documented in the api under AyaFile. Provide it with the file Guid and a path and optional new file name and it’s done.

If you want to work with it in memory inside your app in code then use the GetContent which returns the file in a memorystream.

To update an existing AyaFile use the method SetContent which accepts a generic stream so you can set it from a file or from a memorystream or from any stream based source.

Example:

AyaFileList afl = AyaFileList.GetList(TheWikiPage.ID);

                    foreach (AyaFileList.AyaFileListInfo i in afl)

                    {

                        //Do it in memory way

                        AyaFile af = AyaFile.GetItem(i.LT_O_AyaFile.Value);

                        MemoryStream ms = af.GetContent();

                        //do something with the content

                        af.SetContent(ms);

                        af.Save();



                        //OR



                        //Do it on disk way

                        //like this if you just need to write it out once

                        AyaFile.GetAndWriteFileToDisk(i.LT_O_AyaFile.Value, "c:\	emp\\", "OptionalNewFilename.tmp");



                        //or like this if you want to write it out then save it back later

                        AyaFile af = AyaFile.GetItem(i.LT_O_AyaFile.Value);

                        af.WriteToDisk("c:\	emp\\", "OptionalNewFilename.tmp");

                        //work with the file on disk until ready to store it back in AyaFile..

                        af.SetContent(File.ReadAllBytes("c:\	emp\\whateverthenameofthefileis.xxx"));

                        af.Save();                           



                    }

John

The examples you provided helped a lot. Sometimes an example can bridge the gap between what the API documentation is saying and what I am understanding. With this, I think I have all the pieces to complete my puzzle (project). Thanks Glenn