Skip to main content

Posts

Showing posts from May, 2007

VALIDATING FILE UPLOAD ASP.NET

Using the file upload in ASP.NET control is easy as ABC but there are times when you will like to validate the file type that is being uploaded and the size of the file remembering the fact that there is a maximum file size allowed in the server's config file. I will demonstrate with an image upload control (imgUpload) that stores image on a database. I am trying to ensure that only gif, png or jpg are allowed and maximum size of 300Kb. if (newFileName.EndsWith(".gif") newFileName.EndsWith(".png") newFileName.EndsWith(".jpg")) { #region Image size if (this.imgUpload.PostedFile.ContentLength { using (BinaryReader reader = new BinaryReader(imgUpload.PostedFile.InputStream)) { //Add Image byte[] img = reader.ReadBytes(imgUpload.PostedFile.ContentLength); HealthOrganisationImageFacade image = new HealthOrganisationImageFacade(); HealthOrganisationImageDTO pix = new HealthOrganisationImageDTO(0, OrganisationID, img, Organisation.Text, imgUpload.PostedFile.C...

ADD VOICE (SPEECH) CAPABILITY TO YOUR ASP.NET

Adding speech functionality to your site is so easy using the COM API available in the SAPI has a text-to-speech engine (TTS). Mind you every machine with Windows XP has SAPI and TTS. All you need do is to add a reference to a COM dll available in Microsoft Speech Object Library. The dll's name is Interop.SpeechLib.dll Namespace declare your dll as using SpeechLib; Create a text box that will contain your text, add a button that will trigger the voice conversion as shown below: protected void btnVoice_Click(object sender, EventArgs e) { SpVoice voice = new SpVoice(); try { voice.Speak(spText.Text, SpeechVoiceSpeakFlags.SVSFDefault); } catch (Exception ex) { throw ex; } } QED. You are done now. Just make sure your speakers are on and you have got the right volume.