|
I wrote a function that sends an email on a separate thread in 4.0
I've had trouble with the thread, in getting each one to queue up, but I think I fixed that part.
In the thread, I have a function that reads a HTML file with data fields, and populates the fields with data, I call it my flexible HTML templates. After populating the data, I package the new HTML as the Netmail.Body, to transmit in the message.
So on this message, I send a copy to 3 people, and every once in a while on the 2nd and 3rd copy of the message, it bombs reading the file, because the file is locked or something.
Looking for any ideas on how to fix it.
I'm not sure if I should focus on the file i/o, or on the thread itself, or scrap the idea completely.
Just a general idea of what I'm doing
try
'Read the Html Template from App_Data, and format the template fields
htmlStream = New FileStream(m_PhysicalPath, FileMode.Open, FileAccess.Read)
Dim htmlLen As Long = htmlStream.Length
Dim fileData As Byte() = New Byte(htmlLen) {}
htmlStream.Read(fileData, 0, htmlLen)
If Not (htmlStream Is Nothing) Then htmlStream.Close()
Dim byteLine() As Byte = New Byte() {}
Dim strArray() As String = New String() {}
For bdx As Integer = 0 To fileData.Length - 1
Dim byteVal As Byte = fileData(bdx)
If Not (byteVal = &HD) Then
Array.Resize(byteLine, byteLine.Length + 1)
byteLine(byteLine.Length - 1) = byteVal
Else
Array.Resize(byteLine, byteLine.Length + 1)
byteLine(byteLine.Length - 1) = byteVal
Dim charLine() As Char = New Char() {}
Array.Resize(charLine, byteLine.Length + 1)
For cdx As Integer = 0 To byteLine.Length - 1
charLine(cdx) = AsciiByteToChar(byteLine(cdx))
Next
Dim value As String = New String(charLine)
Array.Resize(strArray, strArray.Length + 1)
strArray(strArray.Length - 1) = value
Array.Resize(byteLine, 0)
bdx += 1
End If
Next
Catch ex As Exception
m_html_Template = New StringBuilder
m_html_Template.Append("load_HTML_Template_Checkout_Complete general error")
dwExitCode = 1
Finally
If Not (htmlStream Is Nothing) Then
htmlStream.Close()
htmlStream.Dispose()
htmlStream = Nothing
End If
End Try
|
|
|
|
|
Not sure if it will help, but you can replace that entire block of code with:
Try
Dim strArray() As String = File.ReadAllLines(m_PhysicalPath)
Catch ex As Exception
m_html_Template = new StringBuilder
m_html_Template.Append("load_HTML_Template_Checkout_Complete general error")
dwExitCode = 1
End Try
http://msdn.microsoft.com/en-us/library/system.io.file.readalllines.aspx[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'll give that a try.
I think my problem is with storing data in the heap, for the thread to access, and I changed some of the data in it.
So when I passed data to the function, inside the function I change the heap data and it crashed.
Which I now question, do I really need to pass data to a function within the thread, and just use the data I stored when calling the thread?
|
|
|
|
|
As crazy as it sounds, I've had problems with File IO and my solution was to introduce a sleep(1000) in the loop after closing the file. It worked for me.
Give it a shot.
|
|
|
|
|
Hi,
I have an HTML element defined as :
<textarea id="txtOrdersNotResult" runat="server" rows="5" cols="15" visible="false"></textarea>
when certain condition hold true, it triggers the textarea to be visible. Then it should set a value in this area, like
txtOrdersNotResult.Value = "this is a test"
I have also tried,
txtOrdersNotResult.InnerText = doesnotexist.ToString();
this area is empty.
any ideas?
|
|
|
|
|
You shared your requirement and not the issue you are facing while implementing it.
Now 2 things:
1. Don't use visible attribute. It will not even render the control and thus will not be accessible through JavaScript. Use style attribute 'display'
style="display:none" , set it to display:block to show.
2. to set the value in it, use attribute value (starts with small V)
txtOrdersNotResult.value = "this is a test"
Hope both the tips should be enough for you to implement it.
|
|
|
|
|
I don't think he's talking about javascript, does he?
Help people,so poeple can help you.
|
|
|
|
|
Ali Al Omairi(Abu AlHassan) wrote: he's talking about javascript, does he?
Yes, he is. See the reference of InnerText (which clearly tells it's JS)
|
|
|
|
|
|
Yep.
|
|
|
|
|
Sir;
You said:
when certain condition hold true, it triggers the textarea to be visible.
Please elaborate or show me your code.
Help people,so poeple can help you.
|
|
|
|
|
Thank you for all your help!
This web application is written in C#, I should have specified that. So, the small and big "V" would not have been an issue.
Also, "InnerText" is a property of of the textarea. Not Javascript.
Solved this problem by using an asp:Literal tag.
Thank you!
|
|
|
|
|
so, your problem was that the tag
<textarea id="TextBox1" runat="server" ></textarea>
generates an object of type HTMLGenericControl.
when the page is first loaded, the server want mention the control in the response if TextBox1.Visible is set to false, nor in the viewstate. So, when the TextBox1.Visible is set again to true on the button click request the server wont load TextBox1's properties of TextBox1 from the request so they need to be set again.
Help people,so poeple can help you.
|
|
|
|
|
Hi all,
m having problem with the following code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim a As New DataSet1.TasksDataTable()
Dim adp As New DataSet1TableAdapters.TasksTableAdapter
adp.Fill(a)
GridView1.DataSource = a
GridView1.DataBind()
GridView1.Visible = True
End Sub
I created a dataset in visual studio by drag n drop. It has got two tables: Tasks and Reply. I saved the dataset by name Dataset1.xsd.
The problem is that the gridview doesn't show up at all. without throwing any errors.
please help.
|
|
|
|
|
Resolved! In GridView
it was AutoGenerateColumns="False"
I changed it to AutoGenerateColumns="True"
.........
Silly Mistake!
|
|
|
|
|
Hello All,
I'm try to show images from database in a client side, but, I have been using many kinds of examples that I found and none work, none of the images shown. The last example I saw it's this:
Auto-bind byte[] to asp:Image[^]
I understand perfectly the example, but the images are still not displayed.
Someone help me a bit with this issue?
In summary, I'm use a HTML5 drag & drop files. Send the files via XMLHttpRequest in a FormData object. One handler take this files in byte() and store in SQL DataBase.
Client code:
$("#btnUploadFile").click(function () {
if (files.length <= 0) {
alert("Debe seleccionar algún fichero para subirlo.");
} else {
var expID = $("#ContentPlaceHolder1_hfExpId").val();
var formData = new FormData();
for (var i = 0; i < files.length; i++) {
alert(files[i].name);
formData.append('file', files[i]);
}
var xhr = new XMLHttpRequest();
xhr.open('POST', "FileHandler.ashx", true);
xhr.overrideMimeType('text/plain; charset=x-user-defined-binary');
xhr.setRequestHeader("ExpedienteID", expID);
xhr.onload = function () {
if (xhr.status === 200) {
RefreshFilePanel();
} else {
console.log('Something went terribly wrong...');
}
};
xhr.send(formData);
};
Handle code:
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim documentBytes As Byte()
Dim lExpId As String = context.Request.Headers("ExpedienteID")
Dim fLenght As Integer
If (context.Request.Files.Count > 0) Then
Dim files As HttpFileCollection = context.Request.Files
For i = 0 To files.Count - 1
fLenght = files(i).ContentLength
documentBytes = New Byte(fLenght - 1) {}
context.Request.InputStream.Read(documentBytes, 0, fLenght)
UploadDocumentBy_ExpID(documentBytes, files(i).FileName, "Description" & lExpId.ToString, lExpId)
Next
End If
End Sub
More late, I try to put this byte() in a image tag on grid.
aspx code:
<asp:GridView ID="grdDocumentoByExp" runat="server" AutoGenerateColumns="false" Width="250px"
DataSourceID="dtsDocumentByExpId">
<Columns>
<asp:BoundField DataField="Archivo" HeaderText="Archivo" />
<asp:BoundField DataField="docId" HeaderText="docId" />
<asp:BoundField DataField="Documento" HeaderText="Documento" Visible="false" />
<asp:TemplateField HeaderText="Preview">
<ItemTemplate>
<asp:Image
ID="imgThumb"
runat="server"
ImageUrl='<%# GetImage(Eval("Documento")) %>'
/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
And the function GetImage in codebehind:
Public Function GetImage(image As Object) As String
Return "data:image/gif;base64," & Convert.ToBase64String(DirectCast(image, [Byte]()))
End Function
In all steps, there is no error, but I think that the error is posible located in the byte() file format..but i'm not sure.
Someone help me?
Sorry for my inglish and Thanks.
|
|
|
|
|
does your image really have the content type of 'image/gif'? (in other words does it have the extension .gif? )
Help people,so poeple can help you.
|
|
|
|
|
|
Please do not do this. If anyone has an answer to your question they will post it. If no one has an answer to your question then you are out of luck and will have to try debugging it yourself. Remember that people here offer advice and help in their own time, and at no cost to you, and many of them already have full-time jobs to do during the day.
Use the best guess
|
|
|
|
|
|
Hi,
I'm working on a school managment web application i want to use a html5/css3 login page but i have to verify if the login and password matches the login and password on the database(SQL Server), if the login or the password do not match i have to show a tooltip on the same web page but i don't know how
Please Help Me
Thank You!
modified 7-Mar-22 21:01pm.
|
|
|
|
|
|
You'll have to call a webservice passing in the values submitted. jQuery has an .ajax method which makes calling web services easy. See http://api.jquery.com/jQuery.ajax/[^]
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
As per me you can use Jquery Ajax post and check autentication from SQL Db
|
|
|
|
|
Thank you all for the help i'll use AJAX wit SQL DB
modified 7-Mar-22 21:01pm.
|
|
|
|