|
From: <sv...@de...> - 2005-05-30 21:57:10
|
Author: pcamacho Date: 2005-05-30 17:57:02 -0400 (Mon, 30 May 2005) New Revision: 1208 Modified: humano2/branches/fileupload/components/webTools/Html.cs humano2/branches/fileupload/components/webTools/basePage.cs humano2/branches/fileupload/web/portal/site/createInstance.aspx.cs humano2/branches/fileupload/web/portal/site/readXslt.aspx humano2/branches/fileupload/web/portal/site/updateInstance.aspx.cs humano2/branches/fileupload/web/portal/site/xsl/file.xsl Log: ADD: files are uploaded and stored with a good system name (idEntityOfIns= tance_idAtt_filename) that is unique. Modified: humano2/branches/fileupload/components/webTools/Html.cs =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- humano2/branches/fileupload/components/webTools/Html.cs 2005-05-30 21= :22:10 UTC (rev 1207) +++ humano2/branches/fileupload/components/webTools/Html.cs 2005-05-30 21= :57:02 UTC (rev 1208) @@ -13,6 +13,7 @@ using System; using System.Web; using System.Web.UI.WebControls; +using System.IO; =20 using Humano2.Core; =20 @@ -81,5 +82,31 @@ { objPage.RegisterClientScriptBlock(strId, strJavascript); } - } + =20 + ///<summary> + /// Allows to upload a collection of file in the directory + /// specified in config.xml=20 + ///</summary> + public static void UploadFile(HttpPostedFile file,int idEntity, = string attId, System.Web.HttpResponse Response) + { + string strFileName; =20 + + if (file.FileName !=3D "")=20 + { + strFileName =3D idEntity + "_" + attId + "_" + file.File= Name; + =20 + //Here create a new path with domainId if it does not ex= ists yet + string upLoadPath =3D Config.Instance().GetOption("locat= ions", "uploadPath"); + =20 + try + { + file.SaveAs(upLoadPath + Path.DirectorySeparatorCha= r + strFileName); + } + catch (Exception err)=20 + { + Response.Write("Failed uploading " + strFileName + "= : " + err.ToString()+"<br>"); =20 + } + } + } + } } Modified: humano2/branches/fileupload/components/webTools/basePage.cs =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- humano2/branches/fileupload/components/webTools/basePage.cs 2005-05-3= 0 21:22:10 UTC (rev 1207) +++ humano2/branches/fileupload/components/webTools/basePage.cs 2005-05-3= 0 21:57:02 UTC (rev 1208) @@ -127,6 +127,15 @@ return baseUrl; } =20 + ///<summary> + ///To get the filename that will be used to store files uploaded= by the user + ///<summary> + protected string buildFileName(int idEntity, string attId, strin= g filename) + { + string res =3D idEntity + "_" + attId + "_" + filename; + return res; + } + =20 /// <summary> /// Sends a message to the user (in the browser) /// <param name=3D"message">The message to send</param> Modified: humano2/branches/fileupload/web/portal/site/createInstance.aspx= .cs =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- humano2/branches/fileupload/web/portal/site/createInstance.aspx.cs 20= 05-05-30 21:22:10 UTC (rev 1207) +++ humano2/branches/fileupload/web/portal/site/createInstance.aspx.cs 20= 05-05-30 21:57:02 UTC (rev 1208) @@ -12,6 +12,7 @@ =20 using System; using System.Collections; +using System.Collections.Specialized; using System.ComponentModel; using System.Data; using System.Drawing; @@ -52,7 +53,20 @@ // Create the instance from the user data.. returns the id of the new= instance. int idEntity =3D dbAdapter.CreateInstance(classId, domainId, Request.= Params); =20 - + =20 + //Upload Files if needed + NameValueCollection InstanceParams =3D new NameValueCollecti= on(); + foreach(string attributeId in Request.Files.AllKeys) + { + Html.UploadFile(Request.Files[attributeId],idEntity,attr= ibuteId,Response); + InstanceParams.Add(attributeId,buildFileName(idEntity,at= tributeId,Request.Files[attributeId].FileName)); + } + //Update the instance with the names of files + if(InstanceParams.Count !=3D 0) + { + dbAdapter.UpdateInstance(idEntity, domainId, InstancePar= ams); + } + =20 if(idEntity>0 && classId>0) { try @@ -79,7 +93,7 @@ HttpContext.Current.Response.Redirect(Html.genAbsoluteUrl("/portal/s= ite/Data_structured.aspx?id_entity=3D" + idview + "&classId=3D"+classId))= ; } } - + =20 #region Web Form Designer generated code override protected void OnInit(EventArgs e) { Modified: humano2/branches/fileupload/web/portal/site/readXslt.aspx =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- humano2/branches/fileupload/web/portal/site/readXslt.aspx 2005-05-30 = 21:22:10 UTC (rev 1207) +++ humano2/branches/fileupload/web/portal/site/readXslt.aspx 2005-05-30 = 21:57:02 UTC (rev 1208) @@ -44,11 +44,32 @@ else return "no date"; } </script> + =20 <script language=3D"Javascript"> <!-- Little function fo= r attribute file --> - function FileAttUpdateHidden(value,inputId) + =20 + function GetBaseName(filename) { + var separatorIndex =3D filename.lastIndexOf("/")= ; //Linux + if(separatorIndex =3D=3D -1) + { + separatorIndex =3D filename.lastIndexOf("\\"= ); //Windows + } + if(separatorIndex =3D=3D -1) + { + separatorIndex =3D filename.lastIndexOf(":")= ; //Mac + } + + //Here: remove all chars that are not in [A-Z,a-= z,0-9], _ + =20 + var res =3D filename.substring(separatorIndex + = 1,filename.length); + =20 + return res; + } + =20 + function FileAttUpdateHidden(value,idInstance,idAtt,= inputId) + { var inputRef =3D document.getElementById(inputId= ); - inputRef.value =3D value; + inputRef.value =3D idInstance + "_" + idAtt + "_= " + GetBaseName(value); } </script> =20 Modified: humano2/branches/fileupload/web/portal/site/updateInstance.aspx= .cs =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- humano2/branches/fileupload/web/portal/site/updateInstance.aspx.cs 20= 05-05-30 21:22:10 UTC (rev 1207) +++ humano2/branches/fileupload/web/portal/site/updateInstance.aspx.cs 20= 05-05-30 21:57:02 UTC (rev 1208) @@ -12,6 +12,7 @@ =20 using System; using System.Collections; +using System.Collections.Specialized; using System.ComponentModel; using System.Data; using System.Drawing; @@ -50,6 +51,21 @@ // Create the instance from the user data.. dbAdapter.UpdateInstance(idEntity, domainId, Request.Params); =09 + //Upload Files if needed + NameValueCollection InstanceParams =3D new NameValueCollecti= on(); + foreach(string attributeId in Request.Files.AllKeys) + { + Html.UploadFile(Request.Files[attributeId],idEntity,attr= ibuteId,Response); + InstanceParams.Add(attributeId,buildFileName(idEntity,at= tributeId,Request.Files[attributeId].FileName)); + } + //Update the instance with the names of files + if(InstanceParams.Count !=3D 0) + { + dbAdapter.UpdateInstance(idEntity, domainId, InstancePar= ams); + } + =20 + =20 + =20 int[] formulas =3D dbAdapter.GetAllFormulasForClass(classId); =20 foreach(int formulaId in formulas) Modified: humano2/branches/fileupload/web/portal/site/xsl/file.xsl =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- humano2/branches/fileupload/web/portal/site/xsl/file.xsl 2005-05-30 2= 1:22:10 UTC (rev 1207) +++ humano2/branches/fileupload/web/portal/site/xsl/file.xsl 2005-05-30 2= 1:57:02 UTC (rev 1208) @@ -5,18 +5,19 @@ <xsl:variable name=3D"data" select=3D"/page/classInstance/data/file[id= _entity=3D$idEntity]/data"/> <xsl:variable name=3D"path" select=3D"/page/classInstance/structure/fi= le[id_entity=3D$idEntity]/path"/> <xsl:variable name=3D"sysAttName" select=3D"/page/classInstance/= structure/attribute[id_entity=3D$idEntity]/sysAttName"/> -=09 + <xsl:variable name=3D"instanceEntity" select=3D"/page/classInsta= nce/structure/entity/id_entity" /> + =20 <xsl:choose>=09 <xsl:when test=3D"/page/flagaction=3D'Read'">=09 <a href=3D""><xsl:value-of select=3D"$data"/></a> </xsl:when> <xsl:when test=3D"/page/flagaction=3D'Update'"> - <input name=3D"{$sysAttName}" value=3D"{$data}" type=3D"= file" onchange=3D"FileAttUpdateHidden(this.value,'hidden{$sysAttName}');"= /> - <input type=3D"hidden" name=3D"{$sysAttName}" id=3D"hidd= en{$sysAttName}" /> + <input name=3D"fileUp{$sysAttName}" value=3D"{$data}" ty= pe=3D"file" onchange=3D"FileAttUpdateHidden(this.value,'{$instanceEntity}= ','{$sysAttName}','fileUpload{$sysAttName}');" /> + <input type=3D"hidden" name=3D"{$sysAttName}" id=3D"file= Upload{$sysAttName}" /> </xsl:when> <xsl:when test=3D"/page/flagaction=3D'Create'"> - <input name=3D"{$sysAttName}file" type=3D"file" onchange= =3D"FileAttUpdateHidden(this.value,'hidden{$sysAttName}');"/> - <input type=3D"hidden" name=3D"{$sysAttName}" id=3D"hidd= en{$sysAttName}" /> + <input name=3D"{$sysAttName}" type=3D"file" /> + <!-- <input type=3D"hidden" name=3D"{$sysAttName}" id=3D= "fileUpload{$sysAttName}" /> --> </xsl:when> </xsl:choose> <xsl:if test=3D"/page/flagaction!=3D'Read'"> <!-- Only for creat= e and update --> |