M
michael.bouvard
I'd like to check FileAttached information when validating the form as
the user submit it.
File type (only pictures actually and size of the file)
But when I use "File Attachment Properties" the box "Allow the user to
attach only the following file types" is deactivated and a message is
written saying "Setting allowable file types is not supported in
server forms".
Then I try to use some code instead as :
---------------------------
public void FileAttached_Validating (object sender,
XmlValidatingEventArgs e)
{
string[] authorizedExtension = { "jpg", "jpeg", "png",
"gif", "bmp", "tif", "swf" };
string xPath = "/my:myFields/my:FileAttached"; // the
control to be checked
string extensionOfFileAttached =
GetExtensionOfFileAttached(xPath);
string validatingName = "FileAttachedValidating"; //this
name must be unique and specific to this type of field
string message = string.Empty;
foreach (string extension in authorizedExtension)
{
message += extension;
message += " ";
}
string messageDetail = string.Empty;
RaiseErrorIfExtensionIsNotAuthorized(authorizedExtension,
extensionOfFileAttached, validatingName, xPath, message,
messageDetail);
}
--------------------
When I attach a *.gif file (advisors.gif) for instance and try to
submit the form :
But as soon as the function GetExtensionOfFileAttached(xPath) is reach
(which is just returning the
myString.Substring(myString.LastIndexOf(".") ) I got an error cause
the xPath in that case doesn't contain the
full path of the file (or even the name of the file attached) but
something looking as :
x0lGQRQAAAABAAAAAAAAADY2AAANAAAAYQBkAHY..... (ECT) ... W+P
+9zrfve8773vfw/8AIQAADs=
the byte[] of the file I guess.
Even in my form (under preview) I can see the name and extension of
the file : I can see "advisors.gif" "13.55 KB".
If I looked on the "View Source" I can find this information :
var g_objCurrentFormData = [[],[1,[[[2,[0,["","","",-1],[[3,[[[4,[0,
["","","",-1], ... . (ECT....)
[[[24,[0,["x0lGQRQAAAABAAAAAAAAADY2AAANAAAAYQBkAHYAaQ(ECT....)
002b97W\u002bP\u002b9zrfve8773vfw\u002f8AIQAADs=","","",-1],[[25,
["FileData",["FileData".... (ECT.....)ou8Zag4XYnCBsJ4R0R14b9yA==|
633222634800956462"];
How can I get the extension file and its size (properly) ?
Thanks
the user submit it.
File type (only pictures actually and size of the file)
But when I use "File Attachment Properties" the box "Allow the user to
attach only the following file types" is deactivated and a message is
written saying "Setting allowable file types is not supported in
server forms".
Then I try to use some code instead as :
---------------------------
public void FileAttached_Validating (object sender,
XmlValidatingEventArgs e)
{
string[] authorizedExtension = { "jpg", "jpeg", "png",
"gif", "bmp", "tif", "swf" };
string xPath = "/my:myFields/my:FileAttached"; // the
control to be checked
string extensionOfFileAttached =
GetExtensionOfFileAttached(xPath);
string validatingName = "FileAttachedValidating"; //this
name must be unique and specific to this type of field
string message = string.Empty;
foreach (string extension in authorizedExtension)
{
message += extension;
message += " ";
}
string messageDetail = string.Empty;
RaiseErrorIfExtensionIsNotAuthorized(authorizedExtension,
extensionOfFileAttached, validatingName, xPath, message,
messageDetail);
}
--------------------
When I attach a *.gif file (advisors.gif) for instance and try to
submit the form :
But as soon as the function GetExtensionOfFileAttached(xPath) is reach
(which is just returning the
myString.Substring(myString.LastIndexOf(".") ) I got an error cause
the xPath in that case doesn't contain the
full path of the file (or even the name of the file attached) but
something looking as :
x0lGQRQAAAABAAAAAAAAADY2AAANAAAAYQBkAHY..... (ECT) ... W+P
+9zrfve8773vfw/8AIQAADs=
the byte[] of the file I guess.
Even in my form (under preview) I can see the name and extension of
the file : I can see "advisors.gif" "13.55 KB".
If I looked on the "View Source" I can find this information :
var g_objCurrentFormData = [[],[1,[[[2,[0,["","","",-1],[[3,[[[4,[0,
["","","",-1], ... . (ECT....)
[[[24,[0,["x0lGQRQAAAABAAAAAAAAADY2AAANAAAAYQBkAHYAaQ(ECT....)
002b97W\u002bP\u002b9zrfve8773vfw\u002f8AIQAADs=","","",-1],[[25,
["FileData",["FileData".... (ECT.....)ou8Zag4XYnCBsJ4R0R14b9yA==|
633222634800956462"];
How can I get the extension file and its size (properly) ?
Thanks