Oct 16, 2011, 2:15 PM
[CLOSED] Clone Upload File Field
Attachment 3342Dear All ,
I'm trying to upload more than on file using one upload file field by put files in array list for every time i add new file,
everything is OK but the problem I found that the picture after saving in folder it has different naming for the same picture i added as last one
for example if add 3 different picture with the different name they and save it i'll find the third one repeated 3 time with tree different name
I think i want to (clone()) the fileUplodeField for every uplode but i can't find this method
this is my code aspx:
I'm trying to upload more than on file using one upload file field by put files in array list for every time i add new file,
everything is OK but the problem I found that the picture after saving in folder it has different naming for the same picture i added as last one
for example if add 3 different picture with the different name they and save it i'll find the third one repeated 3 time with tree different name
I think i want to (clone()) the fileUplodeField for every uplode but i can't find this method
this is my code aspx:
<ext:Window IDMode="Static" ID="winUplodeReasearchFile" runat="server" Icon="House"
Title="تحميل ملفات والسكانر" Hidden="true" Height="410px" Width="350px" Modal="true"
Region="Center" AutoScroll="true">
<Items>
<ext:FileUploadField runat="server" MaxLength="1000" ButtonOnly="true" IDMode="Static"
ID="fuResearch" ButtonText="أستعراض">
<Listeners>
<FileSelected Fn="opennewfile" />
</Listeners>
</ext:FileUploadField>
<Buttons>
<ext:Button ID="bttnAddItem" IDMode="Static" runat="server" Text="أضافة" Icon="Add"
Disabled="true">
<Listeners>
<Click Fn="addNewFile" />
</Listeners>
</ext:Button>
<ext:Button ID="bttnRemoveItem" runat="server" Text="حذف" Icon="Delete" Disabled="true">
<Listeners>
<Click Fn="removeFile" />
</Listeners>
</ext:Button>
</Buttons>
</Items>
<ext:Window >
and this is My JavaScript codefunction opennewfile(sender) {
hfUploadType.setValue('1');
var file = Ext.getCmp('fuResearch').value;
Ext.getCmp('bttnAddItem').enable();
Ext.getCmp('fuResearch');
}
//------------Add File------------------//
var loadingMsg = 'يرجى الانتظار جاري أضافة ملف.....';
function addNewFile(attacmentName) {
if (hfUploadType.getValue() == '2') {
if (UploadScanerFile()) {
Ext.getCmp('fuResearch').setValue("");
hfScanerUploadCounter.setValue(hfScanerUploadCounter.getValue() == "" ? 1 : (hfScanerUploadCounter.getValue() + 1));
attacmentName = "ملف السكانر" + '_' + hfScanerUploadCounter.getValue();
var imageInBufferCont = this.theForm.DynamicWebTwain1.HowManyImagesInBuffer;
for (var i = 0; i < imageInBufferCont; i++) {
this.theForm.DynamicWebTwain1.RemoveImage(0);
TotalImage.setValue('0');
}
this.theForm.CurrentImage.value = "0";
Ext.getCmp('bttnAddItem').disable();
}
else {
Ext.getCmp('bttnAddItem').disable();
return;
}
}
if (mItemcollection.items.items.length > 0) {
if (mItemcollection.items.items[0].id == "mItem") {
Ext.getCmp('mItem').getEl().remove();
Ext.getCmp('mItem').destroy();
mItemcollection.doLayout();
}
}
var value = Ext.getCmp('fuResearch').getValue() == "" ? attacmentName : Ext.getCmp('fuResearch').getValue();
var menuItem = new Ext.menu.Item({
text: value,
id: 'mItems' + Ext.getCmp('hfcounter').getValue(),
iconCls: "icon-arrowright",
listeners: {
Click: {
element: 'el',
fn: menuItemClick
}
}
});
Ext.getCmp('hfcounter').setValue(Ext.getCmp('hfcounter').getValue() + 1);
mItemcollection.add(menuItem);
mItemcollection.doLayout();
Ext.getCmp('bttnAddItem').disable();
try {
Ext.getCmp('fuResearch').setValue("");
if (hfUploadType.getValue() == '1') {
Ext.net.DirectMethods.AddnewFiles({ success: function (result) {
}, eventMask: {
showMask: true, msg: loadingMsg
}
});
}
} catch (e) {
}
}
//------------Selected File------------------//
var FileName = ""
var menuItemClick = function (item) {
var c = this.getEl();
if (this.text.indexOf('السكانر') != -1) {
isScanerToDelete.setValue('true');
}
else {
isScanerToDelete.setValue('false');
}
Ext.getCmp('hfitemremove').setValue(item.getItemId());
FileName = item.iconCls;
var x = item.getItemId();
Ext.getCmp('bttnRemoveItem').enable();
mItemcollection.items.items.indexOf(item.getItemId());
}
//------------Remove File------------------//
var loadingMsg = 'يرجى الانتظار جاري حذف ملف.....';
function removeFile() {
if (Ext.getCmp('mItemcollection').items.length > 0) {
for (var i = 0; i < Ext.getCmp('mItemcollection').items.length; i++) {
if (Ext.getCmp('mItemcollection').items.items[i].id == Ext.getCmp('hfitemremove').getValue()) {
var index = i;
break;
}
}
}
Ext.getCmp(Ext.getCmp('hfitemremove').getValue()).getEl().remove();
Ext.getCmp(Ext.getCmp('hfitemremove').getValue()).destroy();
winUplodeReasearchFile.doLayout();
bttnRemoveItem.disable();
if (isScanerToDelete.getValue() == 'false') {
Ext.net.DirectMethods.RemoveFile(index, FileName, { success: function (result) {
}, eventMask: {
showMask: true, msg: loadingMsg
}
});
}
}
and this is my c# codepublic Int32 UplodingFiles(Int64 ResearchID)
{
string fileName = Path.GetFileName(fuResearch.FileName);
FileInfo fInfo = null;
ResearchFiles researchFiles = new ResearchFiles();
researchFiles.Research_ID = ResearchID;
Int32 totalSize = 0;
int fileNumber = 0;
foreach (Ext.Net.FileUploadField aLsF in arrayListStoreFile)
{
if (aLsF.PostedFile.ContentLength > 0)
{
string fn = System.IO.Path.GetFileName(aLsF.PostedFile.FileName);
fInfo = new FileInfo(aLsF.FileName);
fileName = fInfo.Name + "_" + DateTime.Now.ToString("dd-mm-yyy") + "_" + Guid.NewGuid() + fInfo.Extension;
string directory = Request.MapPath("Research_File\\");
try
{
fuResearch.PostedFile.SaveAs(Request.MapPath("Research_File/" + fileName));
}
catch (Exception e)
{
string se = e.Message;
}
researchFiles.Name = fInfo.Name;
researchFiles.ContentSize = aLsF.PostedFile.ContentLength.ToString();
researchFiles.Url = fileName;
if (ResearchFilesManager.Save(researchFiles) > 0)
{
totalSize += aLsF.PostedFile.ContentLength;
fileNumber++;
aLsF.Destroy();
aLsF.Clear();
}
}
}
if (fileNumber > 0)
{
for (int i = 0; i < fileNumber; i++)
{
RemoveFile(i,"Non");
}
}
arrayListStoreFile.Clear();
return totalSize;
}
// ************************************************
[DirectMethod]
public string AddnewFiles()
{
try
{
if (X.IsAjaxRequest == true)
{
arrayListStoreFile.Add(fuResearch);
fuResearch.Destroy();
return ERP.Messages.GetMessage(ERP.Messages.MessageTypes.AddFile);
}
}
catch (Exception err)
{
return err.Message;
}
return "unkown";
}
[DirectMethod]
public string RemoveFile(int index,string fileName)
{
try
{
if (X.IsAjaxRequest == true)
{
if (arrayListStoreFile.Count > 0)
{
arrayListStoreFile.RemoveAt(index);
return ERP.Messages.GetMessage(ERP.Messages.MessageTypes.Delete);
}
else
{
string[] filePaths = Directory.GetFiles(Request.MapPath("Research_File/"));
foreach (string filePath in filePaths)
{
string [] fileNamearray=filePath.Split('\\');
string[] fileNameArray = fileName.Split('*');
if (fileNamearray[fileNamearray.Length - 1] == fileNameArray[0])
{
ResearchFiles researchFiles=new ResearchFiles();
researchFiles.ResearchFiles_ID =long.Parse(fileNameArray[1]);
ResearchFilesManager.Delete(researchFiles);
File.Delete(filePath);
}
}
}
}
}
catch (Exception err)
{
return err.Message;
}
return ERP.Messages.GetMessage(ERP.Messages.MessageTypes.DeleteError);
}
and you can see same this picture i uploaded 3 time but with different name
Last edited by Daniil; Oct 20, 2011 at 6:36 PM.
Reason: [CLOSED]