|
thats a good idea and you can go through these links will help you,
Link 1[^][^]
Link 2[^]
Education is not a way to escape poverty — it is a way of fighting it.
|
|
|
|
|
I´m building a functionality where the website will send emails with attached Excel-files. For some reason this does not work and I have tried to pinpoint the error. The code below runs perfect as long as the string does not exceed 2340 in length. I have been trying for two days to find out why I can not have longer strings than 2340. Any help would be much appreciated.
Using memoryStream As New MemoryStream()
Dim sData As String = "" ' getDataFromFile()
For i = 1 To 2342
sData += "A"
Next
Dim contentAsBytes As Byte() = Encoding.UTF8.GetBytes(sData)
memoryStream.Write(contentAsBytes, 0, contentAsBytes.Length)
' Set the position to the beginning of the stream.
memoryStream.Position = 0
' Create attachment
Dim contentType As New ContentType()
contentType.MediaType = MediaTypeNames.Application.Octet
contentType.Name = "attachment.xls"
Dim attachment As New Attachment(memoryStream, contentType)
' Add the attachment
message.Attachments.Add(attachment)
' Send Mail via SmtpClient
smtpClient.Send(message)
End Using
Error Message:
System.Net.Mail.SmtpException was unhandled by user code<br />
Message="Failure sending mail."<br />
Source="System"<br />
StackTrace:<br />
at System.Net.Mail.SmtpClient.Send(MailMessage message) at _SendMail.btnSendMail_Click(Object sender, EventArgs e) in E:\Visual Studio 2008\XlsMail\Default.aspx.vb:line 55 at System.Web.UI.WebControls.Button.OnClick(EventArgs e) at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)<br />
InnerException: System.IO.IOException<br />
Message="Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond."<br />
Source="System"<br />
StackTrace:<br />
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) at System.Net.DelegatedStream.Read(Byte[] buffer, Int32 offset, Int32 count) at System.Net.BufferedReadStream.Read(Byte[] buffer, Int32 offset, Int32 count) at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine) at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller) at System.Net.Mail.CheckCommand.Send(SmtpConnection conn, String& response) at System.Net.Mail.DataStopCommand.Send(SmtpConnection conn) at System.Net.Mail.SmtpConnection.OnClose(Object sender, EventArgs args) at System.Net.ClosableStream.Close() at System.Net.Mail.MailWriter.Close() at System.Net.Mail.SmtpClient.Send(MailMessage message)<br />
InnerException: System.Net.Sockets.SocketException<br />
ErrorCode=10060<br />
Message="A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond"<br />
NativeErrorCode=10060<br />
Source="System"<br />
StackTrace:<br />
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)<br />
InnerException:
Glenn
|
|
|
|
|
hi ! all
i m devloping a serch file . and i want to break data set through while loop . i have break sentence that i have enter in my search box and show in label but how i break dataset . plz help me how i do for dataset .
i m sending code through i have break sentence and show in the label .
Dim filenameLen, i, j, index, indexarr, count As Integer
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If txtfiledesc.Text <> "" Then
filenameLen = txtfiledesc.Text.Length
indexarr = 0
j = 0
count = 0
For i = 0 To filenameLen - 1
count = count + 1
If Asc(txtfiledesc.Text.Chars(i)) = 32 Then
For index = indexarr To indexarr
fileNamePart(indexarr) = txtfiledesc.Text.Substring(j, count - 1)
Next
indexarr = indexarr + 1
j = i + 1
count = 0
End If
Next
fileNamePart(indexarr) = txtfiledesc.Text.Substring(j, count)
' Dim jim As Integer = fileNamePart.Length
Label1.Text = ""
Dim filterarr, filterarr1 As Integer
For filterarr = 0 To indexarr
If fileNamePart(filterarr).ToString.ToLower = "the" Or fileNamePart(filterarr).ToString.ToLower = "be" Or fileNamePart(filterarr).ToString.ToLower = "is" Or fileNamePart(filterarr).ToString.ToLower = "an" Or fileNamePart(filterarr).ToString.ToLower = "a" Or fileNamePart(filterarr).ToString.ToLower = "are" Or fileNamePart(filterarr).ToString.ToLower = "of" Or fileNamePart(filterarr).ToString.ToLower = "for" Or fileNamePart(filterarr).ToString.ToLower = "in" Or fileNamePart(filterarr).ToString.ToLower = "on" Or fileNamePart(filterarr).ToString.ToLower = "at" Or fileNamePart(filterarr).ToString.ToLower = "to" Or fileNamePart(filterarr).ToString.ToLower = "shall" Or fileNamePart(filterarr).ToString.ToLower = "will" Then
' fileNamePart(filterarr) = fileNamePart(filterarr + 1)
For filterarr1 = filterarr To indexarr - 1
fileNamePart(filterarr1) = fileNamePart(filterarr1 + 1)
Next
fileNamePart(filterarr1 + 1) = Nothing
' ReDim Preserve fileNamePart(fileNamePart.Length - 1)
filterarr = filterarr - 1
End If
Next
Dim ind1 As Integer
For ind1 = 0 To 10
If (fileNamePart(ind1) <> fileNamePart(ind1 + 1)) And (fileNamePart(ind1) <> Nothing) Then
filterfilename.Add(fileNamePart(ind1))
End If
Next
'fileNamePart = DirectCast(Resize(fileNamePart, 5), String())
Dim z As Integer = 0
While z < filterfilename.Count
Label1.Text = Label1.Text & " || " & filterfilename.Item(z) ' fileNamePart(0)
z = z + 1
End While
|
|
|
|
|
This is a disaster
prabhat kumar mokama wrote: If fileNamePart(filterarr).ToString.ToLower = "the" Or fileNamePart(filterarr).ToString.ToLower = "be" Or fileNamePart(filterarr).ToString.ToLower = "is" Or fileNamePart(filterarr).ToString.ToLower = "an" Or fileNamePart(filterarr).ToString.ToLower = "a" Or fileNamePart(filterarr).ToString.ToLower = "are" Or fileNamePart(filterarr).ToString.ToLower = "of" Or fileNamePart(filterarr).ToString.ToLower = "for" Or fileNamePart(filterarr).ToString.ToLower = "in" Or fileNamePart(filterarr).ToString.ToLower = "on" Or fileNamePart(filterarr).ToString.ToLower = "at" Or fileNamePart(filterarr).ToString.ToLower = "to" Or fileNamePart(filterarr).ToString.ToLower = "shall" Or fileNamePart(filterarr).ToString.ToLower = "will" Then
Consider writing code that's not case sensitive, and storing these words somewhere so it's easy to add/remove them
I can't work out the rest, or what you're asking. Perhaps if you point out where in the code you need help ?
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
First of all don't give others code to net.
Second what are you doing in the above code do not matches with your Query.
Third First clear your logic then learn .net and then post a query.
|
|
|
|
|
|
Add column this way
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + filepath + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1;'";
DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OleDb");
DbDataAdapter adapter = factory.CreateDataAdapter();
DbCommand selectCommand = factory.CreateCommand();
selectCommand.CommandText = "SELECT Fname FROM [Sheet1$]";
DbConnection connection = factory.CreateConnection();
connection.ConnectionString = connectionString;
selectCommand.Connection = connection;
adapter.SelectCommand = selectCommand;
DataTable dt = new DataTable();
adapter.Fill(dt);
DataColumn dc = new DataColumn();
dc.ColumnName = "Lname";
dt.Columns.Add(dc);
foreach (DataRow dr in dt.Rows)
{
dr["Lname"] = "LastName";
}
himanshu
|
|
|
|
|
Himanshu,
I see this creates a data table, which isnt what i really wanted to do.
Thanks for the suggestion, but how do i then extend this code to perform the SQLBulkCopy over to the server????
Thanks.
|
|
|
|
|
Hi,
i dont think there is any way to add columns to datareader.
try this
string connectionString1 = @"Data Source='local\SQLEXPRESS';Integrated Security=True;Pooling=False;Initial Catalog='MASTER'";
string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " + filepath + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1;'";
OleDbConnection con=new OleDbConnection(connectionString);
using (OleDbCommand dcmd = new OleDbCommand("SELECT Fname FROM [Sheet1$]",con))
{
try
{
con.Open();
using (OleDbDataReader dreader = dcmd.ExecuteReader())
{
DataRow myNewRow;
DataRow[] drcol ;
DataTable dt = new DataTable();
dt.Columns.Add("Fname");
dt.Columns.Add("Lname");
myNewRow=dt.NewRow();
while (dreader.Read())
{
myNewRow[0] = dreader.GetValue(0).ToString();
myNewRow[1] = "Test123";
dt.Rows.Add(myNewRow);
}
drcol = dt.Select();
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connectionString1))
{
bulkCopy.ColumnMappings.Add("Fname", "FirstName");
bulkCopy.ColumnMappings.Add("Lname", "LastName");
bulkCopy.DestinationTableName = "T_EmpDetail";
bulkCopy.BatchSize = 500;
bulkCopy.WriteToServer(drcol);
}
}
}
finally
{
con.Close();
}
}
himanshu
|
|
|
|
|
I managed to come up with a very similar solution to this but a little simpler since i only need to add a column and populate it, rather than adding new rows.
Ill post the details later.
Thanks again for all the help everyone!
|
|
|
|
|
<asp:LinkButton ID="lnkUpdate" runat="server" OnClientClick='<%#Eval("Sys_TV_Id","return update({0})") %>' OnClick="lnkUpdate_Click">修改</asp:LinkButton>
this linkbutton in repeater.
I do not konw " Eval("Sys_TV_Id","return update({0})") ".
<script type="text/javascript">
function update(ID){
var data=new Array();
if(ID==null ||ID==""){
temps=eval('document.form1.id');
var j=0;
for(var i=0;i<temps.length;i++)
{
if(temps[i].checked==true){
data[j]=temps[i].value;
j++;
}
}
}
else{
data[0]=ID;
}
if(data==""){
alert('请选择操作对象!');return false;
}
else{
$("updateId").value=data;return true;
}
}
</script>
|
|
|
|
|
know means this what dont I. Sorry!!
|
|
|
|
|
Questions is not clear. Could you please elaborate
Education is not a way to escape poverty — it is a way of fighting it.
|
|
|
|
|
the force strong in you is
|
|
|
|
|
For future reference, if you google the Eval method, the MSDN docs give you the overloads.
This evaluates Sys_TV_Id, and puts it in place of {0} in the string provided. In other words, it calls string.Format.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Hi,
I need to display diffrent images in a cell of a gridview according to the value to be filled there.
Eg:
My gridview display:
100 200 400 100 600
200 200 100 400 100
I want to display diffrent images for each number, If 100, image1. for 200, image2...etc.
thks
|
|
|
|
|
in GridView1_RowDataBound event you can check the value of the cell and you can add controls to that cell accordingly
You are best person who knows about your problem.
-------------------------------------------------
More pain more gain
|
|
|
|
|
Then what is the problem, when before bind the Grid, check the value and based on that bind image path with the Grid image control.
|
|
|
|
|
Read this:
http://msdn.microsoft.com/en-us/library/aa479350.aspx[^]
It's definitely nicer to call a code behind method to return the URL, but you can also have the datasource return the image filenames based on content.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Ive got a page which works fine on my home IIS test server but throws a runtime error once ive copied it to shared server.
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
Ive done the custom error thing mentioned above, and set debug to true but It still just shows this generic error. And I cant catch it with a try catch because it happens even before the page load(so I presume its a problem with web.config?).
So how do I turn errors on?
|
|
|
|
|
The best thing is if you can log onto the server and view the site locally on the server, through something like gotomeeting. Failing that, you can probably catch the error in your global.asax file ( and if you don't have one, add one from the add new file, it will fill it for you )
void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs
}
is the event you want to log your error in.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
protected void Application_Error(object sender, EventArgs e)
{
Exception err = Server.GetLastError();
Response.Clear();
Response.Write(("<h1>" + err.InnerException.Message + "</h1>"));
Response.Write("<pre>" + err.ToString() + "</pre>");
Server.ClearError();
}
Thats what I have at the moment but it doesnt change anything. Do I have to declare it in web.config or something?
|
|
|
|
|
|
Thats where I got the above code but it doesnt seem to change anything. Thanks though
|
|
|
|
|