Difference between revisions of "OOP Class14"
Line 1: | Line 1: | ||
[[Category:OOP]] | [[Category:OOP]] | ||
+ | |||
+ | ==Exta Sruff== | ||
+ | |||
+ | ===Send Mail=== | ||
+ | <csharp><% @Page Language="C#" %> | ||
+ | <% @Import Namespace="System.Web.Mail" %> | ||
+ | <% | ||
+ | //set up some strings for the email | ||
+ | |||
+ | string strTo = "only_a_test@fastmail.fm"; | ||
+ | string strFrom = "jeff@interactive.colum.edu"; | ||
+ | string strSubject = "Hi jeff"; | ||
+ | string strBody = "A real nice body text here"; | ||
+ | |||
+ | //Send email | ||
+ | SmtpMail.SmtpServer = "localhost"; | ||
+ | SmtpMail.Send(strFrom, strTo, strSubject, strBody); | ||
+ | %></csharp> | ||
+ | http://iam.colum.edu/oop/classsource/class14/mail.aspx | ||
+ | [[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class14/mail.aspx -source]] | ||
+ | |||
+ | ===Upload a File=== | ||
+ | |||
+ | http uploader | ||
+ | |||
+ | Add executionTimeout and maxRequestLength to the web.config so that large uploads will not fail. | ||
+ | |||
+ | <xml> | ||
+ | <configuration> | ||
+ | <system.web> | ||
+ | <!-- | ||
+ | httpRuntime Attributes: | ||
+ | executionTimeout="[seconds]" - time in seconds before request is automatically timed out | ||
+ | maxRequestLength="[KBytes]" - KBytes size of maximum request length to accept | ||
+ | useFullyQualifiedRedirectUrl="[true|false]" - Fully qualifiy the URL for client redirects | ||
+ | minFreeThreads="[count]" - minimum number of free thread to allow execution of new requests | ||
+ | minLocalRequestFreeThreads="[count]" - minimum number of free thread to allow execution of new local requests | ||
+ | appRequestQueueLimit="[count]" - maximum number of requests queued for the application | ||
+ | enableKernelOutputCache="[true|false]" - enable the http.sys cache on IIS6 and higher - default is true | ||
+ | enableVersionHeader="[true|false]" - outputs X-AspNet-Version header with each request | ||
+ | --> | ||
+ | <httpRuntime | ||
+ | executionTimeout="1200" | ||
+ | maxRequestLength="65536" | ||
+ | /> | ||
+ | </system.web> | ||
+ | </configuration> | ||
+ | </xml> | ||
+ | |||
+ | multipart form | ||
+ | <csharp> | ||
+ | <form enctype="multipart/form-data" runat="server"> | ||
+ | <tr> | ||
+ | <td>Select file to upload:</td> | ||
+ | <td> | ||
+ | <input id="myfile" type="file" runat="server"></td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td> | ||
+ | <input type=button id="btnUploadTheFile" value="Upload" | ||
+ | OnServerClick="btnUploadTheFile_Click" runat="server" /> | ||
+ | </td> | ||
+ | </tr> | ||
+ | </form> | ||
+ | </csharp> | ||
+ | |||
+ | Parse the multipart form and save the file msdn library. System.Web.HtmlInputFile.PostedFile Property | ||
+ | |||
+ | <csharp> | ||
+ | void btnUploadTheFile_Click(object Source, EventArgs evArgs) | ||
+ | { | ||
+ | //Path to save file | ||
+ | string strBaseLocation = "c:\\infod\\dangerdanger\\upload\\"; | ||
+ | |||
+ | if (null != myfile.PostedFile) | ||
+ | { | ||
+ | // Get the HTTP posted file instance (to simplify the code) | ||
+ | HttpPostedFile postedfile = myfile.PostedFile; | ||
+ | |||
+ | // Get the filename | ||
+ | string filename = new System.IO.FileInfo(postedfile.FileName).Name; | ||
+ | string filesize = postedfile.ContentLength.ToString(); | ||
+ | try | ||
+ | { | ||
+ | myfile.PostedFile.SaveAs(strBaseLocation+filename); | ||
+ | txtOutput.InnerHtml = "File " + strBaseLocation + filename + " uploaded successfully"; | ||
+ | } | ||
+ | catch (Exception e) | ||
+ | { | ||
+ | txtOutput.InnerHtml = "Error saving " + strBaseLocation + filename + " | ||
+ | "+ e.ToString(); | ||
+ | } | ||
+ | |||
+ | //Do some other stuff | ||
+ | //maybe like send an email to let admin know file was uploaded | ||
+ | } | ||
+ | } | ||
+ | </csharp> | ||
+ | |||
+ | http://iam.colum.edu/oop/classsource/class14/up.aspx | ||
+ | [[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class14/up.aspx up.aspx - source]] | ||
+ | [[http://iam.colum.edu/oop/gbrowser.php?file=/classsource/class14/web.config web.config - source]] | ||
+ | |||
+ | ==Final Review== | ||
+ | |||
+ | Be very familar with c# syntax | ||
+ | |||
+ | Understand Classes and inhertance. | ||
+ | |||
+ | Use some advanced class features such as abstract classes and virual methods that are overridden | ||
+ | |||
+ | Understand class relationships | ||
+ | |||
+ | Is A | ||
+ | Has A | ||
+ | Uses A | ||
+ | |||
+ | Be able to read UML Diagrams | ||
+ | |||
+ | |||
class 14 | class 14 |
Revision as of 16:31, 2 May 2006
Exta Sruff
Send Mail
<csharp><% @Page Language="C#" %> <% @Import Namespace="System.Web.Mail" %> <%
//set up some strings for the email string strTo = "only_a_test@fastmail.fm"; string strFrom = "jeff@interactive.colum.edu"; string strSubject = "Hi jeff"; string strBody = "A real nice body text here"; //Send email SmtpMail.SmtpServer = "localhost"; SmtpMail.Send(strFrom, strTo, strSubject, strBody);
%></csharp> http://iam.colum.edu/oop/classsource/class14/mail.aspx [-source]
Upload a File
http uploader
Add executionTimeout and maxRequestLength to the web.config so that large uploads will not fail.
<xml> <configuration>
<system.web> <httpRuntime executionTimeout="1200" maxRequestLength="65536" /> </system.web>
</configuration> </xml>
multipart form <csharp> <form enctype="multipart/form-data" runat="server"> <tr>
<td>Select file to upload:</td> <td> <input id="myfile" type="file" runat="server"></td>
</tr> <tr>
<td> <input type=button id="btnUploadTheFile" value="Upload" OnServerClick="btnUploadTheFile_Click" runat="server" /> </td>
</tr> </form> </csharp>
Parse the multipart form and save the file msdn library. System.Web.HtmlInputFile.PostedFile Property
<csharp> void btnUploadTheFile_Click(object Source, EventArgs evArgs) {
//Path to save file string strBaseLocation = "c:\\infod\\dangerdanger\\upload\\"; if (null != myfile.PostedFile) { // Get the HTTP posted file instance (to simplify the code) HttpPostedFile postedfile = myfile.PostedFile; // Get the filename string filename = new System.IO.FileInfo(postedfile.FileName).Name; string filesize = postedfile.ContentLength.ToString(); try { myfile.PostedFile.SaveAs(strBaseLocation+filename); txtOutput.InnerHtml = "File " + strBaseLocation + filename + " uploaded successfully"; } catch (Exception e) { txtOutput.InnerHtml = "Error saving " + strBaseLocation + filename + "
"+ e.ToString();
} //Do some other stuff //maybe like send an email to let admin know file was uploaded }
} </csharp>
http://iam.colum.edu/oop/classsource/class14/up.aspx [up.aspx - source] [web.config - source]
Final Review
Be very familar with c# syntax
Understand Classes and inhertance.
Use some advanced class features such as abstract classes and virual methods that are overridden
Understand class relationships
Is A Has A Uses A
Be able to read UML Diagrams
class 14