How Can I replace Files With Regex? - asp.net

I have an aspnet webform application and I have more than 1000 server.transfer like below
Server.Transfer("~/General/Personnel/List.aspx");
I want to add /V2 after "~" in all files.
Expected is
Server.Transfer("~/V2/General/Personnel/List.aspx");
This is only sample so I have different folder structure like General/Users/Personnel, Customer/Personnel, Users/List/Personnel only /Personnel is common for every server transfer I want to add /V2 after "~" in all files which contains "/Personnel". How Can I do this with regex or another else in visual studio.

If you want to add “/V2” before all files containing /Personnel, you can try this regex to replace them.
You can click Ctrl+Shift+F to open this window and replace ~/(.*)/Personnel into ~/V2/$1/Personnel

Related

How Can I exclude some files in visual studio finding?

I have a project in asp.net web form and I want to search all files which contains "~/Products" with ctrl+shift+f but I want to exclude a file which is Server.Transfer("~/Products"). I tried regex but it did not work. How Can I do this with regex or something else?
I tried
*~/Products*;!*Server.Transfer("~/Products")*;
If you want to search all files which contains "~/Products" and exclude a file which is Server.Transfer("~/Products").
You can try this regex:
^((?!Server\.Transfer).)*~/Products((?!Server\.Transfer).)*$

How to exclude subfolders and files in the Search pane of LightTable?

What is the syntax of the Locations field in the Find and Replace pane of LightTable? (which appears when hitting CTRL-SHIFT-F, or CTRL+SPACE then Searcher: show)
I would like to exclude all files of the docs/ subfolder, as well as all *.txt and *.csv files of my workspace. What should I enter in the Locations field to exclude them from a search & replace?
Or inversely, I'd like to include only the files from the src/ subfolder. How would I accomplish that?
There doesn't seem to be a way to exclude directories or file patterns right now. However, you can specify which directories to include. You will have to write the whole path though (relative paths use Light Table's application directory). If you want to have more than one path you can separate them by using a comma:
/absolute/path/to/first/dir, /absolute/path/to/second/dir

Combine two config files as an a single file

I have a project with 3 subprojects:AdminPages, UserPags ,UIpages,each part has a separate files.for example AdminPages is coded by MVC4, Userpages and Uipages is coded by ASP web form .
So i have 2 config files,my question is can i combine these two files into single file?Or i have to put each project in a special subdomain ?
Thanks.If i can i will add config files to this post.
With a little google, I came to an answer where it was stated that you can use: XmlConfigMerge.
A qoute from the site:
The XmlConfigMerge utility (provided both as a library assembly and as a console application) supports this merging of XML .config files, and also supports setting of specific parameters via XPath filtering and optional Regex pattern matching.
Go there and try their code and documentation. Good luck!

How can I rename a file in ASP.NET?

In my project I want to rename the file before it is updating. For example a file in my system like Mycontact.xls. I want to rename it as sasi.xls (it is an excel file). How can I write the code in ASP.NET?
Actually I am using a fileupload control to get the file in and rename the file and upload the renamed file in a folder which is in Solution Explorer.
You can do it with the File.Move method eg:
string oldFileName = "MyOldFile.txt";
string newFileName = "MyNewFile.txt";
File.Move(oldFileName, newFileName);
C# does not provide a file rename function, unfortunately. Anyhow, the idea is to do this:
File.Copy(oldFileName, NewFileName);
File.Delete(oldFileName);
You can also use - File.Move.
Be aware that when that code executes, the owner of the file will turn into the identity you have set on your Application Pool on which the website is running.
That account might not have enough permissions to 'create new' or 'delete' files.
I would advise you to place all read/writable files in a seperate location so you can control the security settings seperately on that part. This will also split off the 'only readable files/executables' (like the aspx and such) from the 'read/writable' files.

ASP.NET localized files

I've got a web page with a link, and the link is suppose to correspond to a PDF is the given user's language. I'm wondering where I should put these PDF files though. If I put them in App_LocalResources, I can't specify a link to /App_LocalResources/TOS_en-US.pdf can I?
The PDF should definitely not be in the App_LocalResources folder. That folder is only for RESX files.
The PDF files can go anywhere else in your app. For example, a great place to put them would be in a ~/PDF folder. Then your links will have to be dynamically generated (similar to what Greg has shown):
string cultureSpecificFileName = String.Format("TOS_{0}.pdf", CultureInfo.CurrentCulture.Name);
However, there are some other things to consider:
You need a way to ensure that you actually have a PDF for the given language. If someone shows up at your site and has their culture specified as Klingon, it's unlikely that you have such a PDF.
You need to decide exactly what the file format will be. In the example given, the file would have to be named TOS_en-US.pdf. It you want to use the 2-letter ISO culture names, use CurrentCulture.TwoLetterISOLanguageName and then the file name would be TOS_en.pdf.
I would store the filename somewhere with an argument in it (i.e. "TOS_{0}.pdf" ) and then just add the appropriate suffix in code:
string cultureSpecificFileName = string.Format("TOS_{0}.pdf", CultureInfo.CurrentCulture);
Does the PDF have to have the same file name for each of the different languages? If not, put them all into a directory and just store the path in your resources file.

Resources