IUserResourceSetImage Method |
Set the value of the resource as an image.
Namespace:
AskiaPortalCmn
Assembly:
AskiaPortalCmn (in AskiaPortalCmn.dll) Version: 1.7.0-build068
Syntax IReturnValue SetImage(
string fileName,
byte[] bytes
)
Function SetImage (
fileName As String,
bytes As Byte()
) As IReturnValue
IReturnValue^ SetImage(
String^ fileName,
array<unsigned char>^ bytes
)
Parameters
- fileName
- Type: SystemString
Name of the image file (including the extension) - bytes
- Type: SystemByte
Array of bytes that represent the image
Return Value
Type:
IReturnValueReturn success value if the user in the context have enough permission to do that action.
Remarks Remarks
It will not save the change in the database
unless you explicitly call the
Save method.
Examples Set the resource as an image
var httpRequest = HttpContext.Current.Request;
if (httpRequest.Files.Count != 1)
{
throw new Exception("No image or too many image found in the request. The request accept exactly 1 image file.");
}
var imageFile = httpRequest.Files[0];
var binaryReader = new BinaryReader(imageFile.InputStream);
var bytes = b.ReadBytes(imageFile.ContentLength);
var context = ContextFactory.CreateByLoginOrEmailAndPassword("login", "secret");
var user = context.User;
var resource = user.Avatar;
var result = resource.SetImage(imageFile.FileName, bytes);
if (!result.Success)
{
throw result.Exception;
}
See Also