I have been trying to make a program and it saves mechanics invoices. So I have got this far;
oWord.Application.ActiveDocument.SaveAs2("C:/BMW/Invoices/" + Regbox.Text + "/thing.doc");
which saves the word doc in a folder that is specified by the registration of the bike - this works fine. but what I really want is the date to be used as a filename...I couldn't figure that out, so I made a date label and plan on using the text from it as the filename instead (I know, its a long way round...but it works). Anyways, I have tried;
oWord.Application.ActiveDocument.SaveAs2("C:/BMW/Invoices/" + Regbox.Text + "/" + label19.Text + ".doc");
this was an "invalid filename"
oWord.Application.ActiveDocument.SaveAs2("C:/BMW/Invoices/" + Regbox.Text + "/label19.Text.doc");
this saved it as "label19.Text.doc"
oWord.Application.ActiveDocument.SaveAs2("C:/BMW/Invoices/" + Regbox.Text + "/" + label19.Text, ".doc");
This threw the error "(DISP_E_TYPEMISMATCH)"
All I need to do is get label19 text to work as a filename with a .doc extension...or another way of getting the date as a filename
If you need to use current date as file name then you can use:
oWord.Application.ActiveDocument.SaveAs2("C:/BMW/Invoices/" + Regbox.Text + "/" + DateTime.Now.ToString("MM-dd-yyyy") + ".doc")
Generate the file name in an string variable:
string filename = "C:/BMW/Invoices/" + Regbox.Text + "/" + DateTime.Now.ToString("MM-dd-yy");
and then pass it to SaveAs2 method:
oWord.Application.ActiveDocument.SaveAs2(filename, ".doc");
Related
I am trying to move multiple files in a directory to an archive sub folder. I used a foreach loop to do the idea. Unfortunately, It can only move a file if there is only one file in the directory. But when I put multiple in the directory the Directory.move(); won't work. Can anyone help me?
static string antJsonSerializer(){
#region KDI SALES
string[] allfiles = Directory.GetFiles(#"C:\xml\"); // Put all file names in root directory into array.
string sourceDirectory = #"C:\xml\";
string destinationDirectory = #"C:\xml\Archive\";
// Check if directories are existing -- Working
bool xmlRoot = System.IO.Directory.Exists(sourceDirectory);
if (!xmlRoot) System.IO.Directory.CreateDirectory(sourceDirectory);
bool xmlArchive = System.IO.Directory.Exists(destinationDirectory);
if (!xmlArchive) System.IO.Directory.CreateDirectory(destinationDirectory);
AntHelpers drone = new AntHelpers();
foreach (string name in allfiles)
{
try
{
drone.xmltosql(#name.Trim());
//File.Move(#name, destinationDirectory + (DateTime.Now.Year).ToString() + (DateTime.Now.Month).ToString().PadLeft(2, '0') + (DateTime.Now.Day).ToString().PadLeft(2, '0') + (DateTime.Now.Hour).ToString().PadLeft(2, '0') + ".html"); //Not working
Directory.Move(#name, destinationDirectory + (DateTime.Now.Year).ToString() + (DateTime.Now.Month).ToString().PadLeft(2, '0') + (DateTime.Now.Day).ToString().PadLeft(2, '0') + (DateTime.Now.Hour).ToString().PadLeft(2, '0') + ".html");
//Directory.Move(sourceDirectory, destinationDirectory); //Not working
}
catch (Exception e)
{
//Console.WriteLine("Main Process Catch ERR: " + e.Message);
//ErrLogtoDB(string TRNTYPE, string extserial, string texttowrite, string logfilename)
AntHelpers.ErrLogtoDB("SALES", #name, "Ant JSON Serializer Failed: " + e.Message,
"LeafCutterLogFile_JSONSerializer_" + (DateTime.Now.Year).ToString() + (DateTime.Now.Month).ToString().PadLeft(2, '0') + (DateTime.Now.Day).ToString().PadLeft(2, '0') + (DateTime.Now.Hour).ToString().PadLeft(2, '0') + ".html");
}
//drone.ExtractSQLSendAntHill(); //For testing: OFF
#endregion
return " !!!! Work Complete !!!! ";
}
You are trying to save a file with year + month + day + hour.html as "NAME". If multiple files are there, then how can you save it with same file name? Instead you should add seconds and/or milliseconds, or use something else to distinguish the file and make it a unique name. Otherwise, take file name without the extension then add year, month, day, and hour. That is why you are not able to move multiple files at a time, because when try to move the second file an exception will be thrown say "unable to move an existing file."
Directory.Move takes a source and destination directory, not a file path. Try this:
Directory.Move(sourceDirectory, destinationDirectory);
Also, it can be run at the very end - after the foreach loop.
I have a simple web form where a person can enter into a textbox what kind of project they want. For example, they may type in: Sales & Projection report needs to be fixed.
They then click a submit button and it gets sent off to a third party website that keeps track of our projects.
The problem is, in the example given above, everything gets cut off after the '&' symbol.
it gets sent like this:
String request = "fct=createorcopyproject&guid=" + guid + "&projectname=" + TxtProjectName.Text + "&projectdesc=" + TxtDescription.Text +
"&nexttasknumber=1&budgethours=0&budgetcost=0&estimatedstartdate=" + year + "-" + month + "-" + day + "&estimatedenddate=" + year + "-" + month + "-" + day + "&estimatedhours=0&estimatedexpenses=0&projectpriorityid=" + priorityIndex + "&projectstatusid=NULL&projecttemplate=0&contactname=" + user +
"&defaultestimatedtime=0&defaulttaskstartdate=1&defaulttaskenddate=1&defaulttaskactualdates=2&clientid=" + areaIndex + "&createdefaults=True&languagedefaults=EN&projecttemplateid=0000003&keeptemplatelink=false©projectassignments=True©projectdocuments=True©forumtopics=False©tasks=False&adjusttaskdates=False©taskdocuments=False©taskassignments=False&markproject=False&format=ds";
Where TxtDescription.Text is where we are getting the cutoff.
Is this something on their end or am I missing something?
Use HttpUtility.UrlEncode method to encode the values you send in an URL (assuming this is an URL)
foreach (string TempSize in sizeArr)
{
txtResult.Text += store + "\t" + attributeSet + "\t" + configurableAttri + "\t" + type + "\t" + (ID + "_" + TempColour + TempSize) + "\n";
}
I am trying to generate Multiple Rows that i can use to paste into excel file. "\n" doesn't seem to show on the "new line" of the textbox.
I tried manually doing "\n" aka shift+enter and copy paste the 3 rows into excel, Excel place a empty space between each of them, anyway to remove that problem too?
Thanks in advance!
Problem Fixed with "\r\n" instead of "\n" hat's how Windows controls represent newlines
I want to specify a virtual path of a file but I am not able to do so.
Here is my code:
int Course_Id = 1;
int PortfolioID=1;
int ChandidateID=1;
string filepath = Server.MapPath("~/ePortfolio/PortFolioContent/" + Course_Id + "/Assignments/Exhb_" + item.PortfolioID + "_" + item.ChandidateID + ".jpg");
if(System.IO.File.Exists((filepath)))
{
ViewBag.Thumbnail = filepath;
}
When i use Server.MapPath it is fetching data from some other path:
My original path is:
E:\HOBBYHOMES(E-PORTFOLIO)\HobbyHomesWebApp\ePortfolio\PortFolioContent\1\Assignments
but it is taking this path
E:\HOBBYHOMES(E-PORTFOLIO)\HobbyHomesWebApp\ActivityPostin\Images\ePortfolio\PortFolioContent\1\Assignments\Exhb_1_1.jpg
I m not understanding why this is workin so.Please help me
Try string filepath = Server.MapPath("~/... ...jpg");
You can use #Url.Content("~/Content/Images/YourImageName.png")
Try doing something like this:
Path.Combine(Server.MapPath("~/"),("ePortfolio\\PortFolioContent\\" + Course_Id + "\\Assignments\\Exhb_" + item.PortfolioID + "_" + item.ChandidateID + ".jpg"));
In theory it results in the same answer that failed you previously. In practice, it may yield a completely different answer.
There's also a recent question here (which I can't find at the moment) which highlights that sometimes Server.MapPath("~/..etc..") misbehaves on rewritten request paths. Are you rewriting the request that is trying to form this path?
I want to insert blank characters in a string move to next line and align right in Html editor ajax control and it should be hardcoded in my below code .
My code is
Editor1.Content = "No. J/" + DropDownList3.SelectedItem + "-" + TextBox1.Text + "-" + tyear + "/" + " " + "/" + year + DateTime.Now.Day+"/"+DateTime.Now.Month+"/"+DateTime.Now.Year;
What i want is
i want 5 blank spaces after
....+ tyear + "/" + "....
Move to next/new line after
....." + "/" + year +....
Apply Align left to this entire
content
To add blank spaces to the keyword. Normal blank spaces will be ignored as whitespace by the HTML parser.