PDA

View Full Version : [CLOSED] [#479] MultiUpload error when selected something



CPA1158139
May 04, 2014, 6:34 PM
It displays an error when I Upload a file after clicked and selected a treePanel or gridPanel in a window.
pls see my code.Please click on the button [showWindow], and then click a row,then upload a file.


error :Unexpected character encountered while parsing value: %. Path '', line 0, position 0.

[Description("Serializes the Json object to a specific object.")]
public static object Deserialize(string value, Type type, JsonSerializerSettings settings)
{
return JsonConvert.DeserializeObject(value, type, settings ?? JSON.CurrentSettings);
}
http://forums.ext.net/attachment.php?attachmentid=10401&stc=1



<%@ Page Language="C#" %>

<script runat="server">

protected void Page_Init(object sender, EventArgs e)
{
Form1.Controls.Add(GridMultiUpload());
MultiUpload MultiUpload1 = X.GetCmp<Ext.Net.MultiUpload>("MultiUpload1");
if (MultiUpload1.IsInForm == true)
{
MultiUpload1.FileUpload += MultiUpload1_FileUpload;
}
}

public GridPanel GridMultiUpload()
{
GridPanel GridPanel1 = new GridPanel();
Store Store1 = new Store();

GridPanel1.ID = "UploadGrid";
GridPanel1.Frame = true;
GridPanel1.Width = 520;
GridPanel1.Height = 300;

Toolbar Toolbar1 = new Toolbar();
Toolbar1.ID = "Toolbar1";

ToolbarSeparator ToolbarSeparator1 = new ToolbarSeparator();
Toolbar1.Items.Add(ToolbarSeparator1);

Ext.Net.Button btn1 = new Ext.Net.Button();
MultiUpload MultiUpload1 = new MultiUpload();
MultiUpload1.FormID = "Form1";
MultiUpload1.ID = "MultiUpload1";
MultiUpload1.FileUploadLimit = 50;
MultiUpload1.FileSizeLimit = "15 MB";
MultiUpload1.FileTypes = "*.*";
MultiUpload1.FileDropAnywhere = true;
MultiUpload1.AutoStartUpload = false;
MultiUpload1.FileTypesDescription = "All Files";
MultiUpload1.FileQueueLimit = 0;

MultiUpload1.Listeners.FileSelected.Fn = "fileSelected";
MultiUpload1.Listeners.UploadStart.Handler = "updateRecord(file.id, 'status', 'Sending');";
MultiUpload1.Listeners.UploadProgress.Handler = "updateRecord(file.id, 'progress', Math.round(bytesComplete / bytesTotal));";
MultiUpload1.Listeners.UploadComplete.Handler = @"updateRecord(file.id, 'progress', 1 );updateRecord(file.id, 'status', 'Uploaded' );";

MultiUpload1.Listeners.SwfUploadLoadFailed.Fn = "loadFailed";
MultiUpload1.Listeners.UploadAborted.Handler = "updateRecord(file.id, 'status', 'Aborted');";
MultiUpload1.Listeners.UploadRemoved.Handler = "var store = this.up('grid').store; store.remove(store.getById(file.id));";
MultiUpload1.Listeners.UploadError.Fn = "uploadError";
MultiUpload1.Listeners.FileSelectionError.Fn = "fileSelectionError";

Toolbar1.Items.Add(MultiUpload1);

ToolbarSeparator1 = new ToolbarSeparator();
Toolbar1.Items.Add(ToolbarSeparator1);

btn1 = new Ext.Net.Button();
btn1.ID = "BtnUpAdd";
btn1.Icon = Icon.DiskUpload;
btn1.Handler = "#{MultiUpload1}.startUpload();";
Toolbar1.Items.Add(btn1);

ToolbarSeparator1 = new ToolbarSeparator();
Toolbar1.Items.Add(ToolbarSeparator1);

btn1 = new Ext.Net.Button();
btn1.ID = "BtnUpDel";
btn1.Icon = Icon.Decline;

Toolbar1.Items.Add(btn1);
ToolbarSeparator1 = new ToolbarSeparator();
Toolbar1.Items.Add(ToolbarSeparator1);

ToolbarFill ToolbarFill1 = new ToolbarFill();
Toolbar1.Items.Add(ToolbarFill1);

GridPanel1.TopBar.Add(Toolbar1);

GridHeaderContainer ColumnModel1 = new GridHeaderContainer();
string strColName = string.Empty;
string strColNames = string.Empty;
string strLenth = string.Empty;
string strCtrlType = string.Empty;
Ext.Net.Column cl = new Column();
Ext.Net.DateColumn col = new DateColumn();
Ext.Net.Model md = new Model();
md.ID = "Model1";
Ext.Net.ModelField mf = new ModelField();

mf = new ModelField();
mf.Name = "id";
md.Fields.Add(mf);
mf = new ModelField();
mf.Name = "name";
md.Fields.Add(mf);
mf = new ModelField();
mf.Name = "size";
md.Fields.Add(mf);
mf = new ModelField();
mf.Name = "status";
md.Fields.Add(mf);
mf = new ModelField();
mf.Name = "progress";
md.Fields.Add(mf);
md.IDProperty = "id";
Store1.Model.Add(md);

cl = new Column();
cl.ID = "Column1";
cl.Text = "name";
cl.DataIndex = "name";
cl.Width = 150;
ColumnModel1.Columns.Add(cl);
cl = new Column();
cl.ID = "Column2";
cl.Text = "size";
cl.DataIndex = "size";
cl.Width = 50;
cl.Renderer.Format = RendererFormat.FileSize;
ColumnModel1.Columns.Add(cl);
cl = new Column();
cl.ID = "Column3";
cl.Text = "&nbsp;";
cl.DataIndex = "status";
cl.Width = 50;
cl.Renderer.Fn = "statusIconRenderer";
ColumnModel1.Columns.Add(cl);
cl = new Column();
cl.ID = "Column4";
cl.Text = "status";
cl.DataIndex = "status";
cl.Width = 50;
ColumnModel1.Columns.Add(cl);
ProgressBarColumn cl1 = new ProgressBarColumn();
cl1.ID = "ProgressBarColumn1";
cl1.Text = "progress";
cl1.DataIndex = "progress";

ColumnModel1.Columns.Add(cl1);

GridPanel1.Store.Add(Store1);
GridPanel1.ColumnModel.Columns.AddRange(ColumnMode l1.Columns);

return GridPanel1;
}


protected void MultiUpload1_FileUpload(object sender, FileUploadEventArgs e)
{
string str1 = e.FileName;
X.Msg.Notify("File is uploaded", "Name: " + e.FileName).Show();
}

public class Company
{
public Company(string name, double price, double change, double pctChange)
{
this.Name = name;
this.Price = price;
this.Change = change;
this.PctChange = pctChange;
}

public string Name { get; set; }
public double Price { get; set; }
public double Change { get; set; }
public double PctChange { get; set; }
}

protected void Page_Load(object sender, EventArgs e)
{
this.Store2.DataSource = new List<Company>
{
new Company("3m/Co", 71.72, 0.02, 0.03),
new Company("Alcoa/Inc", 29.01, 0.42, 1.47),
new Company("Altria/Group/Inc", 83.81, 0.28, 0.34)
};

this.Store2.DataBind();
}


</script>

<!DOCTYPE html>

<html>
<head id="Head1" runat="server">
<title>Grid MultiUpload - Ext.NET Examples</title>
<link href="/resources/css/examples.css" rel="stylesheet" />
<script type="text/javascript">
var loadFailed = function () {
alert("Something went wrong while loading SWFUpload. If this were a real application we'd clean up and then give you an alternative");
};

var statusIconRenderer = function (value) {
switch (value) {
default:
return value;
case 'Pending':
return '<img src="' + Ext.net.ResourceMgr.getIconUrl("Hourglass") + '" width=16 height=16>';
case 'Sending':
return '<div src="x-loading-indicator" width=16 height=16>';
case 'Error':
return '<img src="' + Ext.net.ResourceMgr.getIconUrl("Decline") + '" width=16 height=16>';
case 'Cancelled':
case 'Aborted':
return '<img src="' + Ext.net.ResourceMgr.getIconUrl("Decline") + '" width=16 height=16>';
case 'Uploaded':
return '<img src="' + Ext.net.ResourceMgr.getIconUrl("Tick") + '" width=16 height=16>';
}
};

var updateRecord = function (id, field, value) {
var rec = App.UploadGrid.store.getById(id);
rec.set(field, value);
rec.commit();
};

var abortUpload = function (btn) {
var selModel = btn.up('grid').getSelectionModel(),
records;

if (!selModel.hasSelection()) {
Ext.Msg.alert('Error', 'Please select an upload to cancel');
return true;
}

records = selModel.getSelection();
App.MultiUpload1.abortUpload(records[0].getId());
};

var removeUpload = function (btn) {
var selModel = btn.up('grid').getSelectionModel(),
records;

if (!selModel.hasSelection()) {
Ext.Msg.alert('Error', 'Please select an upload to remove');
return true;
}

records = selModel.getSelection();
App.MultiUpload1.removeUpload(records[0].getId());
};

var fileSelected = function (item, file) {
//Example of cancelling a file to be selection
if (file.name == 'image.jpg') {
Ext.Msg.alert('Error', 'You cannot upload a file named "image.jpg"');
return false;
}

this.up('grid').store.add({
id: file.id,
name: file.name,
size: file.size,
status: 'Pending',
progress: 0
});
};

var uploadError = function (item, file, errorCode, message) {
updateRecord(file.id, 'progress', 0);
updateRecord(file.id, 'status', 'Error');

switch (errorCode) {
case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:
alert("Error Code: HTTP Error, File name: " + file.name + ", Message: " + message);
break;
case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:
alert("Error Code: Upload Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
break;
case SWFUpload.UPLOAD_ERROR.IO_ERROR:
alert("Error Code: IO Error, File name: " + file.name + ", Message: " + message);
break;
case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:
alert("Error Code: Security Error, File name: " + file.name + ", Message: " + message);
break;
case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
alert("Error Code: Upload Limit Exceeded, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
break;
case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:
alert("Error Code: File Validation Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
break;
case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
updateRecord(file.id, 'status', 'Cancelled');
break;
case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
updateRecord(file.id, 'status', 'Stopped');
break;
default:
updateRecord(file.id, 'status', "Unhandled Error: " + errorCode);
alert("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
break;
}
};

var fileSelectionError = function (item, file, errorCode, message) {
if (errorCode === SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) {
alert("You have attempted to queue too many files.\n" + (message === 0 ? "You have reached the upload limit." : "You may select " + (message > 1 ? "up to " + message + " files." : "one file.")));
return;
}

switch (errorCode) {
case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
alert("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
break;
case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
alert("Error Code: Zero byte file, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
break;
case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
alert("Error Code: Invalid File Type, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
break;
default:
alert("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
break;
}
};
</script>
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />

<ext:Store ID="Store2" runat="server">
<Model>
<ext:Model ID="Model2" runat="server">
<Fields>
<ext:ModelField Name="Name" />
<ext:ModelField Name="Price" />
<ext:ModelField Name="Change" />
<ext:ModelField Name="PctChange" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
<br/>
<ext:Button
ID="Button2"
runat="server"
Text="ShowWindow">
<Listeners>
<Click Handler="#{Window2}.show()" />
</Listeners>
</ext:Button>

<br/>
<ext:Window
ID="Window2"
runat="server"
Icon="House"
Title="Click Listener"
Hidden="true"
X="275"
Y="150">
<Items>

<ext:GridPanel
ID="GridPanel2"
runat="server"
StoreID="Store2"
Title="Company List"
Width="600"
Height="350">
<ColumnModel ID="ColModel2" runat="server">
<Columns>
<ext:Column ID="Col1" runat="server" Text="Company" DataIndex="Name" Flex="1" />
<ext:Column ID="Col2" runat="server" Text="Price" Width="75" DataIndex="Price">
</ext:Column>
<ext:Column ID="Col3" runat="server" Text="Change" Width="75" DataIndex="Change">
</ext:Column>
<ext:Column ID="Col4" runat="server" Text="Change" Width="75" DataIndex="PctChange">
</ext:Column>
</Columns>
</ColumnModel>

<SelectionModel>
<ext:RowSelectionModel ID="RowSelectionModel1" runat="server" Mode="Single">
<Listeners>
<Select Handler="alert('it is bad upload when clicked.');#{Window2}.hide();"></Select>

</Listeners>
</ext:RowSelectionModel>
</SelectionModel>
</ext:GridPanel>


</Items>


</ext:Window>

</form>
</body>
</html>

Daniil
May 05, 2014, 7:49 AM
Hi @CPA1158139,

Thank you for the report. Reproduced. Created an Issue:
https://github.com/extnet/Ext.NET/issues/479

We are investigating.

Daniil
May 05, 2014, 8:20 AM
It has been fixed in the SVN trunk the revision #5823. Please update.

CPA1158139
May 05, 2014, 9:43 AM
It works fine.

Thank you very much.

pls close