Yes. I was able to fix this issue. The above code was correct, the only exception of "File was closed" was giving me trouble. Fixed it by keeping the file stream opened while sending(SMPTPClient.send()) the email. Thanks for the help.
NJdotnetdev
Posts
-
Long Path Exception when adding attachments -
Long Path Exception when adding attachmentsCan someone please advise? Really appreciate your time and help.
-
Long Path Exception when adding attachmentsI am getting a long path exception while adding attachments to MailMessage. Our file path exceeds 260, but that's how it is and we want it to work. Following is what I have done to avoid the exception:
private void CreateAttachments(MailMessage mailMessage, List filesToAdd)
{
foreach (string fileToAdd in filesToAdd)
{
SafeFileHandle fileHandle = null;
try
{
fileHandle = Common.CreateFile(Common.prefixPath(fileToAdd), Common.GENERIC_READ, FileShare.Read, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero);
if (!fileHandle.IsInvalid)
{
using (FileStream fs = new FileStream(fileHandle, FileAccess.Read))
{
Attachment data = new Attachment(fs, fileToAdd);
mailMessage.Attachments.Add(data);
}
}
}
finally
{
if ((fileHandle != null) || fileHandle.IsInvalid)
fileHandle.Dispose();
}
}
}Above LOC doesn't throw an exception while adding attachments. But, while sending(smtpClient.Send(mailMessage)) it throws an exception "Failure Sending Mail". UPDATED CODE
-
Compress pdf/csv files to zip filesI am using System.IO.Compression to create zip file of PDF or CSV files. I used CompressionLevel.Optimal to maximize the compression ratio. However, the percent of compression is 10-12%. Was wondering if there is another efficient way to do it? Framework: 4.5
-
How to get scrollbars in TGridPanel?I am trying to get two columns in TGridPanel, where user will be able to drag , drop and move around GUI components(TImage) at runtime. I can drag and drop, however TGridPanel doesn't show scrollbars when I drop a lot of elements. It starts to shrink the ones already init. To have scrollbars I added this grid panel on TScrollBar and changed "Align" property to "alClient". My plan is to save the final setting of components in a 2D array. My plan is to have at least one component per row to save the row of TGridPanel.
-
Group by - Custom functionI have following row data in a json file: {rows:[ {id:1,data:["1","A","10"]} ,{id:2,data:["2","B","50"]} ,{id:3,data:["3","C","60"]} ,{id:4,data:["4","D","70"]} ,{id:5,data:["5","E","90"]} ,{id:6,data:["6","F","2"]} ,{id:7,data:["7","G","4"]} ,{id:8,data:["8","H","50"]} ,{id:9,data:["9","B","100"]} ,{id:10,data:["10","A","60"]} ,{id:11,data:["11","K","0"]} ,{id:12,data:["12","L","20"]} ]} I was wondering if I can get a kick start suggestion to write our own group by function to group on any column. Like in above example, we can use the second column to group by. The only restriction I have is that I can't use jquery and have to use java script only. Need expert help...
-
Write log from multiple instances of an application.Quick question: Will there be a problem if multiple instances of the same application try to write in the same flat file at the same time? I found following text on MSDN: You should not configure more than one Flat File sink or Rolling Flat File sink instance to write to the same physical file. However, you can enable the same listener (and sink) on multiple event sources and funnel the events from those multiple event sources to the same file. Link: Logging events to a disk file[^]
-
Write log from multiple instances of an application.Thanks a lot Richard for the advise. Will look in to it. :) :)
-
Write log from multiple instances of an application.My C# dll is loaded by an application. I wanted to add logging in the dll. The only question in mind is how I can make sure that only one instance of the loaded dll is writing to the log file at a given time. I found following approaches while searching, but not 100% sure if they would help: 1. Use FileShare Enumeration: But, this might cause problem if the first process hangs and blocks the resource. 2. Use Mutex: It was recommended to not use as it doesn't help when there are multiple processes accessing the same file. It is helpful when multiple threads are accessing the same file. Since, I can be wrong in my assumption so wanted to ask experts for some advise. Thanks.
-
Load XML string in to TTreeViewThanks a lot for the help.
-
Conditional RunTime codeIt's managed and loaded once at a given time.
-
Conditional RunTime codePlease correct me if it's a bad approach: I was thinking to set a boolean flag variable/property in overloaded function. This variable/property can be defined in a common static class. Finally, use this flag to execute LOC selectively.
-
Conditional RunTime codeI am implementing this for the first time, so need expert advise. Following is what I am trying to achieve: -- I have a dll which is called by the exe application from two different places. My aim is to not call certain loc in dll when it is called from the first location. I don't think conditional directives will help as they would not compile the code. I want to skip loc at runtime based on the call from the application. Dll will have an overloaded function implemented to distinguish between the calls.
-
Get X Axis label and interval400 value is in example. I came up with those numbers to explain what I am trying to achieve. Actually, I did figure this out. Thanks.
-
Get X Axis label and intervalHi All, I am trying to come up with an algorithm to get following three piece of information to plot a chart: 1. Start : Should be close to the minimum value of the dataset 2. Stop : Should be close to the maximum value of the dataset 3. Interval : Should be such that it will have "0" on the axis when interval traverses from minimum to maximum. Example: dataset{-266,-17.6,0.5,2000,6000} My final return values should be: Start: 400 Stop: 6000 Interval:200 Note: Since start is 400 and interval is 200, we will have 0 as a point on the x-axis.
-
Get Axis intervalSure... Will do that...
-
Get Axis intervalI am going to implement this is javascript. We have data in csv format which will be read by the JS function and the start, stop and interval will be sent to third party library to create chart. The algorithm I am looking for can be pseudo code. It's not specific to JS, but would be a big help to know if some one would have implemented this using JS.
-
Get Axis intervalHi All, I am trying to come up with an algorithm to get following three piece of information to plot a chart: 1. Start : Should be close to the minimum value of the dataset 2. Stop : Should be close to the maximum value of the dataset 3. Interval : Should be such that it will have "0" on the axis when interval traverses from minimum to maximum. Example: dataset{-266,-17.6,0.5,2000,6000} My final return values should be: Start: 400 Stop: 6000 Interval:200 Note: Since start is 400 and interval is 200, we will have 0 as a point on the x-axis.
-
Browser ResizeThanks for the reply. I also didn't like the idea. :)
-
Browser ResizeI want to restrict user at certain height and width. Tried implementing window.ResizeTo, but it doesn't work on chrome and when multiple tabs are open. My goal is NOT allow user to shrink browser window beyond certain height and width. Please Advise.