Recently, I encountered the problem of storing the image into the server and then reading it to datalist.
Page:
<Div style = "margin-top: 20px">
<Asp: datalist id = "datalist1" runat = "server" repeatdirection = "horizontal" repeatcolumns = "3">
<Itemtemplate>
<Div style = "width: 600px">
'width = "200" Height = "200"/>
<Br/>
<% # Eval ("FILENAME") %>
</Div>
</Itemtemplate>
</ASP: datalist>
</Div>
Background:
Datatable dt = new datatable ();
DT. Columns. Add ("FILENAME ");
DT. Columns. Add ("filepath"); // display
String imageurl = "/userdata/uploadimg/"; // Application Path
String imgpath = server. mappath (imageurl); // The obtained path is the physical path on the server, that is, the absolute path.
If (string. isnullorempty (this. chosedate. Text ))
{
Response. Write ("<SCRIPT> alert ('select date') </SCRIPT> ");
Return;
}
Datetime chosedate = datetime. parse (this. chosedate. Text); // time range
// If (string.isnullorempty(this.txt machine. Text ))
//{
// Response. Write ("<SCRIPT> alert ('Enter the machine Code') </SCRIPT> ");
// Return;
//}
String machinecode = this.txt machine. Text. Trim (); // machine code
String imagedire = chosedate. tostring ("yyyymmdd"); // The get time folder is 20140603.
// Find the folder that meets the conditions
String searchfilename = machinecode + "_" + imagedire; // machine code + 20140202
// Path
String imagepathroot = configurationmanager. receivettings ["imagepathroot"]; // userdata/uploadimg
String machineimagepathroot = configurationmanager. appsettings ["machineimagepath"]; // C: \ myprojects \ su8pad \ SRC \ hotelpadsolution \ hotelpadweb \ userdata \ uploadimg \
// Returns the file list
String fullfilepath = machineimagepathroot + imagedire;
If (! Directory. exists (fullfilepath) // No file comes in
{
Response. Write ("<SCRIPT> alert ('file does not exist') </SCRIPT> ");
Return;
}
String [] pathlist = directory. getfiles (fullfilepath); // static
// Search for images
For (INT I = 0; I <pathlist. length; I ++)
{
Pathlist [I] = pathlist [I]. Replace (@"\","/");
String filename = pathlist [I]. substring (pathlist [I]. lastindexof ('/') + 1); // file name
// Specifies the date when the object is intercepted.
String tempfilenamecode = filename. substring (filename. indexof ('_') + 1 );
String filenamedate = tempfilenamecode. substring (0, tempfilenamecode. lastindexof ('.'));
Filenamedate = filenamedate. substring (0, 8 );
Filenamedate = filenamedate. insert (4 ,"-");
Filenamedate = filenamedate. insert (7 ,"-");
Datetime currentfiledate = datetime. parse (filenamedate );
String tempmachinecode = filename. substring (0, filename. indexof ('_'); // machine code
// Obtain the date difference
Timespan Ts = new timespan ();
TS = chosedate-currentfiledate;
If (TS. totaldays = 0 & (filename. Contains (machinecode) | machinecode = "") // fuzzy
{
Datarow DR = DT. newrow ();
Dr [0] = filename;
Dr [1] = imagepathroot + imagedire + "/" + filename; // pathlist [I];
DT. Rows. insertat (DR, DT. Rows. Count );
}
}
This. datalist1.datasource = DT;
This. datalist1.databind ();
}
View datalist images based on conditions