I am trying to use a basic if else case, but the if is executed no matter what.
This is the code found in the backend, on the aspx.cs file.
if (1==2)
{
// 22/09/2014 12:00:00 AM for en
//format date for submit
Dateformatted = this.DateField.Value.ToString();
DateSplit = Dateformatted.Split('/');
yearAt0 = DateSplit[2].Split(' ');
Datetosubmit = yearAt0[0] + "/" + DateSplit[1] + "/" + DateSplit[0] + " 00:00:00";
}
else
{
// 2014-09-22 00:00:00 for fra
//format date for submit
Dateformatted = this.DateField.Value.ToString();
DateSplit = Dateformatted.Split('-');
dayAt0 = DateSplit[2].Split(' ');
Datetosubmit = DateSplit[0] + "/" + DateSplit[1] + "/" + dayAt0[0] + " 00:00:00";
}
This is the error I get (line 1209 is red):
System.IndexOutOfRangeException: Index was outside the bounds of the array.
Line 1207: string Dateformatted = this.DateFieldEdit.Value.ToString();
Line 1208: string[] DateSplit = Dateformatted.Split('/');
Line 1209: string[] yearAt0 = DateSplit[2].Split(' ');
Line 1210: string Datetosubmit = yearAt0[0] + "/" + DateSplit[1] + "/" + DateSplit[0] + " 00:00:00";
Line 1211:
This clearly indicates that the code inside the false part of the if statement was executed. Is there a reason for this? How can I fix this?
Note: The if (1==2) was added to simplify the example, it is normally a parameter
You can see this effect if your binaries and your PDB files are out of sync. If you are using the updated PDBs, but the old binaries, that would definitely explain this scenario.
The easiest way to fix this to to completely clean and rebuild everything. Deleting everything in your bin and obj folders for good measure. You should also restart the IIS instance you are using.
Related
I've been using this for a while and it's always worked fine. The project writes to a docx log file as it runs. I recently made a modification to the path it writes the log to for someone else to use. Since then, when I run it as a built exe it writes one line per page. But when I attempt to fix the problem, I can't recreate it running it in VS. From there it works like it always had.
Any ideas? A direction someone can point me toward?
public static void WritetoLogFile(string logUpdate)
{
DateTime now = DateTime.Now;
string logDate = now.ToString("MM-dd");
string folderNameDate = now.ToString("MM_dd_yyyy");
string folderName = folderNameDate + "_Logs";
string stateFolder = " ";
System.IO.Directory.CreateDirectory(Crawlspace.networkSharePath + "//" + folderName);
string logName = logDate + "_" + Crawlspace.browser + "_" + Crawlspace.computerName + "_" + Crawlspace.SuiteTable + ".docx";
Crawlspace.LogFileName = logName;
System.IO.Directory.CreateDirectory(Crawlspace.networkSharePath + folderName + "//" + stateFolder);
Crawlspace.LogFile = Crawlspace.networkSharePath + folderName + "//" + stateFolder + "//" + logName;
if (System.IO.File.Exists(Crawlspace.LogFile))
{
using (DocX document = DocX.Load(Crawlspace.LogFile))
{
Paragraph par1 = document.InsertParagraph();
par1.Append(logUpdate);
par1.Font("Courier New");
par1.FontSize(8);
document.Save();
}
}
else
{
using (DocX document = DocX.Create(Crawlspace.LogFile))
{
Paragraph par1 = document.InsertParagraph();
par1.Append(logUpdate);
par1.Font("Courier New");
par1.FontSize(8);
document.Save();
}
}
}
RESOLVED:
I checked the xceed.words.net.docx dll in the nuget manager and found there was an update. Updated to the latest and modified my using statements to reflect the update and it's now working....
using Image = Xceed.Document.NET.Image;
using Paragraph = Xceed.Document.NET.Paragraph;
using Picture = Xceed.Document.NET.Picture;
I am currently working on a project that sweeps a mailbox for attachments and when one is found it is placed in the user's directory. My problem is that when I check if the file exist in the path, I alter the attachment's name and add a counter and time stamp, that way it is not over written. However, when it goes into the condition and changes the file name it never updates the path variable to include the right value of the Clean name variable.
string timeProcessed = DateTime.Now.ToString();
byte[] bytefiles = attachment.ContentBytes;
string cleanName = MakeCleanName(userEmail.Subject, attachment.Name);
string path = employeeStarPath + "\\" + cleanName;
// updated this in order to prevent images with the same name from overwritting eachother.
if (File.Exists(path))
{
cleanName = Path.GetFileNameWithoutExtension(attachment.Name).ToString()+"(" + counter + ")" + "-(Recieved - " + timeProcessed.Replace(":",".").Replace("/",".") + " )"+ Path.GetExtension(attachment.Name); << this value is not updated in the path variable.
}
Now I am aware I can update the path var by calling path = employeeStarPath + "\\" + cleanName; again but I feel that this makes my code a bit confusing.
I might not understood your question but can you just call the line "string path = employeeStarPath + "\" + cleanName;" at the end instead before the if?
string timeProcessed = DateTime.Now.ToString();
byte[] bytefiles = attachment.ContentBytes;
string cleanName = MakeCleanName(userEmail.Subject, attachment.Name);
// updated this in order to prevent images with the same name from overwritting eachother.
if (File.Exists(path))
{
cleanName = Path.GetFileNameWithoutExtension(attachment.Name).ToString()+"(" + counter + ")" + "-(Recieved - " + timeProcessed.Replace(":",".").Replace("/",".") + " )"+ Path.GetExtension(attachment.Name); << this value is not updated in the path variable.
}
string path = employeeStarPath + "\\" + cleanName;
I have a method that runs through a loop that can take quite a while to complete as it requires getting data back form an API.
What I would like to do is display a message on the front end explaining how the system is progressing during each loop. Is there a way to update the front end while processing?
public static void GetScreenshot(List<string> urlList, List<DesiredCapabilities> capabilities, String platform, Literal updateNote)
{
foreach (String url in urlList)
{
String siteName = new Uri(url).Host;
String dir = AppDomain.CurrentDomain.BaseDirectory+ "/Screenshots/" + siteName + "/" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm");
foreach (DesiredCapabilities cap in capabilities)
{
String saveDirectory = "";
if (platform == "btnGenDesktopScreens")
{
saveDirectory = dir + "/" + cap.GetCapability("os") + "-" + cap.GetCapability("os_version") + "-" + cap.GetCapability("browser") + cap.GetCapability("browser_version");
}
else if(platform == "btnMobile")
{
saveDirectory = dir + "/" + cap.GetCapability("platform") + "" + cap.GetCapability("device") + "-" + cap.GetCapability("browserName");
}
updateNote.Text += "<br/>" + cap.GetCapability("platform") + " - " + cap.GetCapability("device") + "-" + cap.GetCapability("browserName");
//I'd like to display a message here
TakeScreenshot(url, cap, saveDirectory);
//I'd like to display a message here
}
}
}
Has anyone come across a method of doing this?
Depending on how you're returning the feedback to the user, you might be able to do this by using HttpResponse.Flush in a loop to push parts of the HTML response to the user a bit at a time. See https://msdn.microsoft.com/en-us/library/system.web.httpresponse.flush(v=vs.100).aspx
I am trying to export the drawing to save another drawing using "CopyBase" and "PasteClip" command. But it is does not work an error occurred. Can anyone tell how to i solve this..
i am using Copy and Paste command like this..
AcadApplication acadApp;
AcadDocument thisdrawing;
acadApp = Marshal.GetActiveObject("AutoCAD.Application.20") as AcadApplication;
acadApp.Visible = true;
thisdrawing= acadApp.ActiveDocument;
thisdrawing.Activate();
string str = "_CopyBase" + char.ConvertFromUtf32(13) + "0,0,0" + char.ConvertFromUtf32(13) + "M" + char.ConvertFromUtf32(13) + "G" + char.ConvertFromUtf32(13) + "QWERT" + "\n" + char.ConvertFromUtf32(13);
thisdrawing.SendCommand(str);
string dwgTempPath = "acad.dwt";
newThisdrawing = acapp.Documents.Add(dwgTempPath ) ;
newThisdrawing.SaveAs(expDwgName , thisdrawing.Application.Preferences.OpenSave.SaveAsType,null);
newDwgCreatBool = true;
newThisdrawing.Regen(AcRegenType.acActiveViewport);
newthisdrawing.Activate();
comStr = "pasteclip" + "\n" + "0,0" + "\n";
newThisdrawing.SendCommand(comStr);
Thanks in Advance..
With your edit, I'm assuming this is an external exe. With that in mind and some minor modifications to your code, I got this to work with no problems in a Console exe. Before the code a couple things about it:
I compiled using the 4.5 Framework. The COM references for .NET may have been updated with their .NET API counterparts, so make sure this is the case for you too.
Add a COM reference to "AutoCAD 2015 Type Library" there's one for each language package (choose axdb20enu.tlb, but I think in the end VS may select them all after it's added).
Add a COM reference to "AcObjClassImp 1.0 Type Library", choose the one for release 20 (AcObjClassImp20.tlb)
Add the using statement "using AutoCAD;" at the top with the rest.
Here's the code I used:
static void Main(string[] args)
{
IAcadApplication acadApp;
IAcadDocument thisdrawing;
acadApp = Marshal.GetActiveObject("AutoCAD.Application.20") as AcadApplication;
acadApp.Visible = true;
thisdrawing = acadApp.ActiveDocument;
thisdrawing.Activate();
string str = "_CopyBase" + char.ConvertFromUtf32(13) + "0,0,0" + char.ConvertFromUtf32(13) + "M" + char.ConvertFromUtf32(13) + "G" + char.ConvertFromUtf32(13) + "QWERT" + "\n" + char.ConvertFromUtf32(13);
thisdrawing.SendCommand(str);
string dwgTempPath = "acad.dwt";
IAcadDocument newThisdrawing = acadApp.Documents.Add(dwgTempPath);
//Instead of the path below, use your full path, formatted correctly
newThisdrawing.SaveAs(#"C:\Acad\Test.dwg", thisdrawing.Application.Preferences.OpenSave.SaveAsType, null);
newThisdrawing.Regen(AcRegenType.acActiveViewport);
newThisdrawing.Activate();
string comStr = "pasteclip" + "\n" + "0,0" + "\n";
newThisdrawing.SendCommand(comStr);
}
I have a folder with files coming in as
fileName(prefix) + " " + todayDate.ToString("yyyyMMdd") + ".csv";
For simple file my regex was FilePrefix + #"(.*)\.csv"
How to have a search pattern to get file for only today's date ?
It sounds like if you're just searching for today's date, then you should already know exactly what file name you're looking for. So there's no need for a regex - just look for files where
var expectedName = FilePrefix + " " + DateTime.Now.ToString("yyyyMMdd") + ".csv";
String.Compare(fileName, expectedName, StringComparison.OrdinalIgnoreCase) == 0
Just do something like this
List<string> fileNames = // wherever you're getting these
var ending = DateTime.Now.ToString("yyyyMMdd") + ".csv";
var filteredFileNames = fileNames.Where(x => x.EndsWith(ending));