Find And Replace Linebreaks In File Read From Disk
Sep 4, 2010
I have a css file which I want to read from disk and in that content I want to find and replace all linebreaks (do I look for vbCrlf or ...?)
Public Shared Function GetFileContents(ByVal FullFilename As String) As String
Dim filecontents As String = ""
If File.Exists(FullFilename) Then
Dim objStreamReader As StreamReader
objStreamReader = File.OpenText(FullFilename)
filecontents = objStreamReader.ReadToEnd()
objStreamReader.Close()
End If
Return filecontents
End Function
So in the returned variable "filecontents" I want to find and replace any linebreaks.
I'm using ASP.NET for file uploads, and I'm hitting a bit of a snag in that data sent by the client as multipart form data is read straight into RAM.
Obviously, this means maximum file upload size is limited to the available RAM on the machine, and even then is much smaller as soon as you have multiple simultaneous uploads.
Is it possible to get ASP.NET to write the data to a temporary file on the hard drive as it is recieved rather than reading into RAM?
I have a lot of requests that read my Web Config file (eg. variable = WebConfigurationManager.AppSettings["BLAH"]). I am wondering... Do WebConfigurationManager.AppSettings read from disk each time, or is it cached in memory. If it's read from disk each time then I guess I will need to move the variable to a static variable so as to improve my app performance...
I need to open and read a Dbase file in my ASP.NET application. When I try to open the connection, I am getting the exception "Could not find installable ISAM." I have tried the solutions in the top answer in this question, but they did not work for me.The filepath of the data file is C:devDATA.DBF. Here is the code I am using to try to open the connection:
Dim connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;DataSource=C:devDATA.DBF;Extended Properties=dBASE IV;" Dim connection As OleDbConnection = New OleDbConnection(connectionString) connection.Open()
I get the exception "Could not find installable ISAM." Do you have any ideas what I can try to get this to work? Note that I am able to import this file into an Access database as a dBASE IV file.
I created 2 functions that do this, but I do not this it efficient at all. I have a 40mb file and it takes the program about 2 hours to complete. Is there a more efficient way to do this? Is there a way to use regex? See my code below:.....................
i'm trying to find all the anchor tags and appending the href value with a variable. for example
<a href="/page.aspx">link</a> will become <a href="/page.aspx?id=2"> <A hRef='http://www.google.com'><img src='pic.jpg'></a> will become <A hRef='http://www.google.com?id=2'><img src='pic.jpg'></a>
I'm able to match all the anchor tags and href values using regex, then i manually replace the values using string.replace, however i dont think its the efficient way to do this.Is there a solution where i can use something like regex.replace(html,newurlvalue)
I have a page with 20 textboxes and rather then write a script for every box ive been looking in to a for loopbelow is what i have so farAm i on the right lines? i cant find what value needs to go after the replace part, thats were im getting my error but not sure im on the right lines anyway!
Dim ctl As Control For Each ctl In Page.Controls(1).Controls If TypeOf ctl Is TextBox Then
I'm using a book to create a shopping site and need to change the following code so that the current dropdown list, of colour options, is replaced by just read only text. I'm a novice and despite best efforts I can't fathom it out. If anyone can change the code for me I would be extremely grateful.
The code below is the code-behind page for a Product List page where I want each product displayed to also display its colour options as just text (I don't need the shopper to select a colour choice until they click through to the detail page)
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; public partial class UserControls_ProductsList : System.Web.UI.UserControl { protected void Page_Load(object sender, EventArgs e) { PopulateControls(); } private void PopulateControls() { // Retrieve DepartmentID from the query string string departmentId = Request.QueryString["DepartmentID"]; // Retrieve CategoryID from the query string string categoryId = Request.QueryString["CategoryID"]; // Retrieve Page from the query string string page = Request.QueryString["Page"]; if (page == null) page = "1"; // Retrieve Search string from query string string searchString = Request.QueryString["Search"]; // How many pages of products? int howManyPages = 1; // pager links format string firstPageUrl = ""; string pagerFormat = ""; // If performing a product search if (searchString != null) { // Retrieve AllWords from query string string allWords = Request.QueryString["AllWords"]; // Perform search list.DataSource = CatalogAccess.Search(searchString, allWords, page, out howManyPages); list.DataBind(); // Display pager firstPageUrl = Link.ToSearch(searchString, allWords.ToUpper() == "TRUE", "1"); pagerFormat = Link.ToSearch(searchString, allWords.ToUpper() == "TRUE", "{0}"); } // If browsing a category... else if (categoryId != null) { // Retrieve list of products in a category list.DataSource = CatalogAccess.GetProductsInCategory(categoryId, page, out howManyPages); list.DataBind(); // get first page url and pager format firstPageUrl = Link.ToCategory(departmentId, categoryId, "1"); pagerFormat = Link.ToCategory(departmentId, categoryId, "{0}"); } else if (departmentId != null) { // Retrieve list of products on department promotion list.DataSource = CatalogAccess.GetProductsOnDeptPromo (departmentId, page, out howManyPages); list.DataBind(); // get first page url and pager format firstPageUrl = Link.ToDepartment(departmentId, "1"); pagerFormat = Link.ToDepartment(departmentId, "{0}"); } else { // Retrieve list of products on catalog promotion list.DataSource = CatalogAccess.GetProductsOnFrontPromo(page, out howManyPages); list.DataBind(); // have the current page as integer int currentPage = Int32.Parse(page); } // Display pager controls topPager.Show(int.Parse(page), howManyPages, firstPageUrl, pagerFormat, false); bottomPager.Show(int.Parse(page), howManyPages, firstPageUrl, pagerFormat, true); } // Executed when each item of the list is bound to the data source protected void list_ItemDataBound(object sender, DataListItemEventArgs e) { // obtain the attributes of the product DataRowView dataRow = (DataRowView)e.Item.DataItem; string productId = dataRow["ProductID"].ToString(); DataTable attrTable = CatalogAccess.GetProductAttributes(productId); // get the attribute placeholder PlaceHolder attrPlaceHolder = (PlaceHolder)e.Item.FindControl("attrPlaceHolder"); // temp variables string prevAttributeName = ""; string attributeName, attributeValue, attributeValueId; // current DropDown for attribute values Label attributeNameLabel; DropDownList attributeValuesDropDown = new DropDownList(); // read the list of attributes foreach (DataRow r in attrTable.Rows) { // get attribute data attributeName = r["AttributeName"].ToString(); attributeValue = r["AttributeValue"].ToString(); attributeValueId = r["AttributeValueID"].ToString(); // if starting a new attribute (e.g. Color, Size) if (attributeName != prevAttributeName) { prevAttributeName = attributeName; attributeNameLabel = new Label(); attributeNameLabel.Text = attributeName + ": "; attributeValuesDropDown = new DropDownList(); attrPlaceHolder.Controls.Add(attributeNameLabel); attrPlaceHolder.Controls.Add(attributeValuesDropDown); } // add a new attribute value to the DropDownList attributeValuesDropDown.Items.Add(new ListItem(attributeValue, attributeValueId)); } } }
using the ajaxControlToolkit requires the ToolkitScriptManager, but then i get the message: "only one scriptmanager..." the problem is, i cant find any other scriptmanager in the whole solution, so it should be somewhere in the parent pages. how can i find/get/replace this scriptmanager-object?
I have a table called 'products'. In each table there is a column named 'description' of type ntext (sql server 2000). The description conains a ton of text and within that text there is an ip address many times. I need to replace every instance of the ip address with the actual domain name, 123.45.678.990 with http://domain.com.
I am using ASP.NET 3.5 with iTextSharp and I have the following code:
var templatePath = Server.MapPath(@"~/Templates/template1.pdf"); var newFilePath = Server.MapPath(@"~/TempFiles/new.pdf"); PdfReader pdfReader = new PdfReader(templatePath); PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream(newFilePath, FileMode.Create)); AcroFields pdfFormFields = pdfStamper.AcroFields; pdfFormFields.SetField("Box1", "007"); pdfFormFields.SetField("Box2", "123456"); pdfStamper.FormFlattening = false; pdfStamper.Close(); Response.ClearContent(); Response.Buffer = true; Response.ContentType = "application/pdf"; Response.AddHeader("Content-Disposition", "attachment;filename=new.pdf")); Response.WriteFile(newFilePath); Response.End();
The above code fills out a pdf file and saves the new file to the TempFiles folder. It then prompts the user to either save or open the file. Can I achieve the same functionality without saving the file to the TempFiles location?
I need to be able to read an excel file from a file upload control but I can not save the file to disk first, it must be done in memory.
[Code]....
Above is my code for reading the data file if it IS saved to disk, but again, I have to be able to do this without saving the file to disk, it must be done in memory. I have not been able to find any sample code anywhere on how to do this from memory, everything seems to force the file be uploaded, saved to disk, and then read in the connection string, which again I can not do.
I've a view which display all data. I'm using ViewData, for loop etc.. on the view, to show the data. It may sound weird, but is it possible to write view to disk as a file instead of showing in the browser. The reason is that, business wants functionality to send the same view file as email attachment to the user.
How to save Ajax Editor content as an HTML file to a disk?
Let's say I have an Ajax Editor which allows user to type or paste in long message or writting. Once he clicks on "submit" button, an HTML file will be created and save to a disk. I am working on asp.net 3.5, ajax version 3.5 (from codeplex, work well).
What are the options for handling file uploads to reduce the memory footprint? Is there a way to upload in chunks? Is there a way to stream upload directly to disk instead of loading entire file in server memory?
i need to save multiple documents stored in SQL server as Image type to disk.
What i want to do is "backup" all files in a table (column) to disk, zip them and Response.TransmitFile(FilePath) to client.
I could use C# ot VB but that would require a lot of connections to database or a lot of server memory and i don't want that, becauze there are a lot of files to be saved Since SQL can write files to disk i was thinking about saving those files to disk directly from sql. Something like when u're doing a backup
I hv a file upload control which save files in folder upload_html. When I upload file of same name which already exists upload_html folder it does't replace that file.........
I want that file to be replaced from that folder.............