Back to Devexpress

IFileData.LoadFromStream(String, Stream) Method

expressappframework-devexpress-dot-persistent-dot-base-dot-ifiledata-dot-loadfromstream-x28-system-dot-string-system-dot-io-dot-stream-x29.md

latest3.4 KB
Original Source

IFileData.LoadFromStream(String, Stream) Method

Loads the file data from a stream.

Namespace : DevExpress.Persistent.Base

Assembly : DevExpress.Persistent.Base.v25.2.dll

NuGet Package : DevExpress.Persistent.Base

Declaration

csharp
void LoadFromStream(
    string fileName,
    Stream stream
)
vb
Sub LoadFromStream(
    fileName As String,
    stream As Stream
)

Parameters

NameTypeDescription
fileNameString

A string that is the file name.

| | stream | Stream |

A Stream that is the file content.

|

Remarks

The example below demonstrates how to use the LoadFromStream method to upload a Contact’s file into a portfolio.

csharp
using System.IO;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using DevExpress.Persistent.BaseImpl;
using MainDemo.Module.BusinessObjects;
// ...
public class UpdatePortfolioController : ObjectViewController<DetailView, Resume> {
    public UpdatePortfolioController() {
        SimpleAction updatePortfolioAction = new SimpleAction(this, "UpdatePortfolio", PredefinedCategory.Edit);
        updatePortfolioAction.SelectionDependencyType = SelectionDependencyType.RequireSingleObject;
        updatePortfolioAction.Execute += updatePortfolioAction_Execute;
    }
    private void updatePortfolioAction_Execute(object sender, SimpleActionExecuteEventArgs e) {
        FileData currentFile = ViewCurrentObject.File;
        if(currentFile != null && !currentFile.IsEmpty) {
            FileData fileCopy = ObjectSpace.CreateObject<FileData>();
            using(var stream = new MemoryStream()) {
                currentFile.SaveToStream(stream);
                stream.Position = 0;
                fileCopy.LoadFromStream(currentFile.FileName, stream);
            }
            PortfolioFileData portfolio = ObjectSpace.CreateObject<PortfolioFileData>();
            portfolio.File = fileCopy;
            ViewCurrentObject.Portfolio.Add(portfolio);
            ObjectSpace.CommitChanges();
        }
    }
}

Here, FileData is a built-in class that implements the IFileData interface.

See Also

File Attachments (Store Custom Files)

File Attachments Module Controllers

IFileData Interface

IFileData Members

DevExpress.Persistent.Base Namespace